• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Reading Windows directory path from .properties file.

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ? :-)
 
Sheriff
Posts: 22042
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic