Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

read/write to .ini file

807600Jul 18 2007 — edited Sep 6 2007
confusion on .ini file

I have a .ini file as such:

StartDate=5/27/2006
LastRunDate=6/18/2007

[OutputDirectory]
LogPath=C:\Me

When I run this code:

import java.util.*;
import java.io.*;

public class readIni {

public static void main(String[] args) {
readIni ini = new readIni();
ini.doit();
}

public void doit() {
try {
Properties properties = new Properties();
properties.load(new FileInputStream("user.ini"));

String string = properties.getProperty("LogPath");
properties.setProperty("LogPath", "test");
properties.store(new FileOutputStream("test.ini"), null);
} catch (IOException e) {
}
}
}

I get the output as such:

#Wed Jul 18 11:01:53 PDT 2007
[OutputDirectory]=
LogPath=test
LastRunDate=6/18/2007
StartDate=5/27/2006

I want it to appear as such:

StartDate=5/27/2006
LastRunDate=6/18/2007

[OutputDirectory]=
LogPath=test

Why do I get the output all mixed up and the add-in date information of
#Wed Jul 18 11:01:53 PDT 2007?

Please help.
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2007
Added on Jul 18 2007
17 comments
5,389 views