Hello
Im trying the ini4j library but I seem to be having problems writing a Unicode file (no problems reading I believe)
Is this a Java issue or ini4j?
Thank you
pretty difficult to say where your problem is ...
what do you mean by: seem to be having problems?
what problem? does it give an error message, if so, which one, ...
it's obviously a Java issue, since ini4j is a Java api, but whether the issue is within ini4j or in your code ...
pretty difficult to say where your problem is ...
what do you mean by: seem to be having problems?
what problem? does it give an error message, if so, which one, ...it's obviously a Java issue, since ini4j is a Java api, but whether the issue is within ini4j or in your code ...
Man I explain things wrong....
Instead of writing in the file
ñ
it puts
\u007a
which I BELIEVE is a ANSI/ASCI code right
Something like
helloñhello
is written as
hello\u007ahello
Anyone have any ideas or tips? I know the FileWriter doesnt support Unicode (dumb on Sun's part) but is there any alternatives? I cant seem to get DataStreamWriter to work correctly with ini4j
Some text and code example:
Here is the contents of the ini name hey.ini lets say:
helloñhello
[section]
x=test
now code:
Ini vini=new Ini();
vini.load(new FileReader("hey.ini"));
String v =vini.get("section").get("x");
System.out.println("The variable contains before saving: " + v);
System.out.println(v.length());
vini.put("section", "x", Integer.parseInt("123"));
//OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("hey.ini"),"UTF-8");
vini.store(new FileOutputStream("hey.ini"));
FileOutputStream file_output=new FileOutputStream("hey.ini");
DataOutputStream data_out=new DataOutputStream(file_output);
vini.store(new OutputStreamWriter(data_out,"UTF-8"));
//vini.store(new OutputStreamWriter("hey.ini","UTF-8"));
vini.load(new FileReader("hey.ini"));
v =vini.get("section").get("x");
System.out.println("The variable contains after saving:: " + v);
System.out.println(v.length());
After running this code, the hey.ini file is:
hello\u007ahello
[section]
x = 123
Fixed.
The correct code is:
Ini vini=new Ini();
vini.load(new FileReader("hey.ini"));
String v =vini.get("section").get("x");
System.out.println("The variable contains before saving: " + v);
System.out.println(v.length());
vini.put("section", "x", Integer.parseInt("123"));
//OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("hey.ini"),"ISO-8859-1");
vini.store(new FileOutputStream("hey.ini"));
FileOutputStream file_output=new FileOutputStream("hey.ini"); DataOutputStream data_out=new DataOutputStream(file_output);
vini.store(new OutputStreamWriter(data_out,"ISO-8859-1"));
//vini.store(new OutputStreamWriter("hey.ini","ISO-8859-1"));
vini.load(new FileReader("hey.ini"));
v =vini.get("section").get("x");
System.out.println("The variable contains after saving:: " + v);
System.out.println(v.length());
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.