• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

properties store

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have program as below:

private Properties props;
........
.........

Vector v;
......
.......
v.add("c:\\tmpdir");
.......
.......
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
props.store(outputStream, "My Properties");


I expect the string stores in the file should be "c:\\tmpdir", but it turns out to be "c\:\\tmpdir" due to props.store(................);
How do I eliminate the the extra backslash(\) following by [b]C[/b]



 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The colon is used as an optional separator for key value pairs.
Have a look at the API (load method), when you load the input into the properties file you would get your original value back.
http://download.oracle.com/javase/1.4.2/docs/api/java/util/Properties.html
have a look at the list method.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Nortje wrote:The colon is used as an optional separator for key value pairs.
Have a look at the API (load method), when you load the input into the properties file you would get your original value back.
http://download.oracle.com/javase/1.4.2/docs/api/java/util/Properties.html
have a look at the list method.



Thank you for trying to help me.

I did put a backslash(\) as c\:\\tmpdir, but I got an error says "Invalid escape sequence.
 
Marshal
Posts: 80128
417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use a single backslash; you have to escape it as \\.
 
Christopher Nortje
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clearly you did not read what I suggested you read.
You can try any variation of escape sequences it won’t work.
If you really need to write only c:\\tmpdir then use:
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? Why does it matter what the value is when printed, or saved to the file? Isn't it more important to get the right value from your code?
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic