• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

properties file editing

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to pass in a key value, and then delete a line inside properties file based on the key. Somehow I can't find any methods to do this in Properties class. Does anyone know how to?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the property does not exist in your map of Properties it will not be saved to a file. So:

should do it.
 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
tried using the following code:

inside the properties there are a few keys and "test" is one of them, if I set fout to true, it will append the whole properties file below without the removed key. But if I don't set fout to true, all the keys and values wil be removed.
Actually I want the original file to be updated. Is it I need to use a workaround, say, store it in a different fout file after removing the key, and then delete the fin file, then rename the fout file to the fin file?
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

inside the properties there are a few keys and "test" is one of them, if I set fout to true, it will append the whole properties file below without the removed key. But if I don't set fout to true, all the keys and values wil be removed.



What do you mean by "set fout to true"? fout is an outputstream, not a boolean variable.


BTW, the properties store() method, just writes the basic properties out to the stream. If the original property file had an ordering, comments, and extra line spaces for readability, they will all be gone. In other words, if you store(), don't expect the property file to be nicely formatted anymore.

Henry
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would strongly advise you don't try to have an InputStream and and OutputStream for the same file at the same time. Depending on the operating system, it may throw an error, or you may get some very strange results. Keep these actions separate: open an input stream, read it, and close it. Then open an output stream, write to it, and close it.

I assume by "set fout to true" you're talking about the FileOutputStream constructor that takes a booolean, for appending. You don't want to append here; you want to write a new file.
 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry, Tim is right about the boolean for fout, I mean the append argument for the constructor, sorry about the lack of info.

Thanks guys, I think I'll use a workaround to get what I want.
[ December 22, 2006: Message edited by: vivien siu ]
 
That new kid is a freak. Show him this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic