Hi all.
I want to read and update a ini file to do some processing. Here is what I have try.
Reading part is ok, it's read all data I want. When I write all content of the ini file is deleted and following is the content.Code:public static void main(String[] args) { // TODO code application logic here new ReadINIFile().readIt(); //new ReadINIFile().writeIt(); } private void readIt() { try { Properties pro = new Properties(); pro.load(new FileInputStream("temp.ini")); // Try to display them System.out.println("Key is: " + pro.getProperty("Key")); System.out.println("Here is: " + pro.getProperty("Here")); } catch(Exception ex) { System.out.println(ex.getMessage()); } } private void writeIt() { // Try to update values try { Properties pri = new Properties(); pri.store(new FileOutputStream("temp.ini"), "Just a comment"); pri.setProperty("Here", "New"); } catch(IOException ioe) { System.out.println(ioe.getMessage()); } }
Can anyone of you tell me where I'm going wrong. Here is the structure of the ini file.#Just a comment
#Fri May 09 10:41:51 IST 2008
[Head]
Text=Java
Key=14
Name=Old
[More]
Here=New




Reply With Quote