File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "" "(space character ) vs   %20" Watch "" "(space character ) vs   %20" New topic
Author

" "(space character ) vs %20

Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
hi guys

i read a propety file from the following path

C:/Documents and Settings/chinnaraj/workspace/email/bin/classes/te.properties

i use the following code to read this property file

ClassLoader cl=Thread.currentThread().getContextClassLoader();
java.net.URL path= cl.getResource("te.properties");
System.out.println(" file "+path);
String s=path.getFile();

by printing s i found %20 in the path like below
file:/C:/Documents%20and%20Settings/chinnaraj/workspace/email/bin/classes/te.properties

what makes the " "(space characters ) changed to %20

when i faced this issue
i used this line s=s.replace("%20", " ");

to break through this
i want to know why the " "(space character) is changed to %20
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
That's because the path gets converted to an URL. Certain characters in URLs are escaped by the percent-sign/hex notation you saw. You can use the java.net.URLDecoder.decode method to reverse this encoding.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Alternatively, you can turn your URL into a File:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
thank you guys

cheers
amir
 
jQuery in Action, 2nd edition
 
subject: " "(space character ) vs %20
 
Similar Threads
How to deploy EJB in weblogic
Setting up Java
Command line, Env Variables
Compiling a Servlet
Trouble with running Maven Tomcat plugin through Eclipse