How to read and write .txt file with keys.?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ananda_Kallugadde
Posted On:   Tuesday, April 17, 2001 05:21 PM

Hi,
I want to write a Java program which will write a text file with key and value(eg, key1=abcd) and also want to read this. Would you please suggest me what is the best way to do this using Java...? Is it good idea to use java.util.Properties class..?

Re: How to read and write .txt file with keys.?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, April 17, 2001 07:12 PM

Hi,

Well, it could be useful. Anyway, this is a piece of code for reading a file into a Properties object and writing it back:


Properties props = new Properties();

try {

    props.load(new FileInputStream(new File());

}

catch (IOException ioE) {

    // do something

}





try {

    FileOutputStream fos = new FileOutputStream(new File());

    props.store(fos, "");

    fos.close();

}

catch (IOException ioE) {

    // do something

}



This is a very raw code and should work, maybe you can think of using better IO classes.
About | Sitemap | Contact