Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Use of properties class

Thread view: 
ffellico@inwind.it - 31 Dec 2005 08:17 GMT
I have the following Ascii file named wscnt:

#Sat Oct 08 08:34:32 CEST 2005

#contatore progressivo corrente
contatore=0000100

#contatore iniziale
iniziale=0000100

#limite contatore
limite=0000110

I like to read the value of "contatore" wich initially is 0000100

Increment it of 1 unit

and write it back in the file wscnt.

I am able to read it but I am unable to rewrite the file updated.

Can anyone write for me the few correct statements to do this?

Thank you and Happy new year. Franco
sherazi - 31 Dec 2005 10:10 GMT
  Hi Franco ;

 String fileName="wscnt.properties";
  FileInputStream fis = new FileInputStream(fileName);
  Properties prop=new Properties();
  prop.load(fis);
  fis.close();
  prop.setProperty("contatore","0000101");
  FileOutputStream fos = new FileOutputStream(fileName);
  prop.store(fos,"");
  fos.close();

  try it it will solve ur problem
ffellico@inwind.it - 01 Jan 2006 10:00 GMT
Thank you sherazi. Naturally it work!

Before I was uncertain about the statement:
prop.store(fos,"");

because I was dubious on what was necessary to put in the second
parameter!

Happy new year. Franco.
Roedy Green - 02 Jan 2006 16:15 GMT
>   prop.store(fos,"");

Beware. This method scrambled the order, turfs you comments and blank
lines. See http://mindprod.com/jgloss/properties.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 02 Jan 2006 14:58 GMT
On 31 Dec 2005 00:17:46 -0800, "ffellico@inwind.it"
<ffellico@inwind.it> wrote, quoted or indirectly quoted someone who
said :

>I like to read the value of "contatore" wich initially is 0000100
>
[quoted text clipped - 7 lines]
>
>Thank you and Happy new year. Franco

You load the properties, then you put a new value for a property, then
you save the properties as a whole. There is no way to just modify a
little piece of the file.

See http://mindprod.com/jgloss/properties.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.