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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading Windows directory path from .properties file." Watch "Reading Windows directory path from .properties file." New topic
Author

Reading Windows directory path from .properties file.

Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
I am trying to read a .properties file through java.util.Properties class. And I have to read a directory path (Windows) as one of the items in the properties file.
So, if have log_dir=D:\log\today, in java I am getting this as - D:logtoday.

I know putting D:\\log\\today is a workaround because of the escape character '\', but this property will be user defined, and I don't know what they will write.

Is there (another) way around this ?

Thanks.
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

It's a bit weird that you let the user to modify the .properties file. Anyway, is it possible to read the .properties file after the user has entered something on the file and replace the "\" with File.separator? If it's not possible, you may want to parse the file manually, create the java.util.Properties, and insert the item by calling put(key, value). That way you have more control on the data.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
Thanks for the reply Freddy.

The code below works and I get the path exactly as written -


but this is so much more work than -



Guess I have no other choice, huh ? :-)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

It's not really more work, it's actually even less work. Well, at least for the JVM. Properties.load does that all that for you, plus more, like handling line breaks in values and other forms of escaping. However, as you are unable to accept that behaviour (especially the escaping) then you have no other choice but to do it manually.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading Windows directory path from .properties file.
 
Similar Threads
Log4j and WSAD 5.0
write a file from liux to windows
Root drive in Unix corresponding to C:/ in Windows
package question
Head First Code