• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

" "(space character ) vs %20

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you can turn your URL into a File:
 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you guys

cheers
amir
 
reply
    Bookmark Topic Watch Topic
  • New Topic