read/write to .ini file

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.

[1195 byte] By [mana07a] at [2007-11-27 10:58:55]
# 1

Properties is-a Map, and the order of entries in a Map is unspecified.

Your code should not reply on the order of entries in a property file.

Hippolytea at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 2

thanks for the feedback.

I am new to Java with 0 experience at that so excuse the dumb questions I may ask.

If the use of properties will not solve my issue, is there another route I can take to solve the problem I have so my output for the .ini looks how I want it to look.

thanks.

mana07a at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 3

If the order of lines is important to you, write it out yourself:

http://java.sun.com/docs/books/tutorial/essential/io/index.html

Hippolytea at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 4

many thanks for the needed direction.

I ended up using BufferedReader and PrintWriter.

Through much trial and error finally able to get it to work where I am able to

-grab the contents of .ini file

-manipulate it

-send it back to same .ini file

thanks again :-)

man07

mana07a at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 5

Perhaps this might be useful:

http://ini4j.sourceforge.net/

prometheuzza at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 6

hmmm.

this looks alot more efficient/cleaner then the method I am taking.

I guess this is the next thing to tackle.

--thanks

mana07a at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 7

what version of jdk do I need for this.

I have version jdk1.5.0_12 and am using eclipse.

i am unable to reference this:

import org.ini4j.Ini;

mana07a at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 8

> what version of jdk do I need for this.

> I have version jdk1.5.0_12 and am using eclipse.

> i am unable to reference this:

>

> import org.ini4j.Ini;

Java 1.5 is probably fine. You just need to add that JAR file you downloaded to your CLASSPATH. In Eclipse, you can do that like this:

- right-click your Eclipse project;

- in the left menu: select "Properties";

- in the next left menu: select "Java Build Path";

- select the "Libraries" tab;

- click the button "Add External JARs...";

- locate the JAR file org.ini4j.Ini is supposed to be in.

prometheuzza at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 9

I don't have a local copy of this.

where can I download this org.ini4j.Ini .jar file?

I checked Sun and was not able to find it.

many thanks.

mana07a at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 10

From sourceforge? Wasn't the URL given already?

BigDaddyLoveHandlesa at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...
# 11

> I don't have a local copy of this.

> where can I download this org.ini4j.Ini .jar file?

> I checked Sun and was not able to find it.

>

> many thanks.

See reply #5. In the top of the page there is a download link.

prometheuzza at 2007-7-29 12:19:33 > top of Java-index,Java Essentials,New To Java...