Use of properties class

F

ffellico

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
 
S

sherazi

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
 
F

ffellico

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.
 
R

Roedy Green

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top