Encoding Problems in JRE
Hello forum, I Have a strange problem regarding Character Encoding while running in JRE, I need to save in a text file some text and I have some special characters in it for control reasons, for ex. the char ( ◙ ).
My problem is that while this works when I run my program through the NetBeans, when I try to run the Jar file with JRE the Special characters become the (TM) char.
Why do you think that happens ?
Thanks in advance.
I might be totally wrong, but have you tried specifically selecting the character encoding for output? I had this problem when I passed some commandline args to program and they turned out odd. I solved the problem using PrintStream. Like so:
System.out.println("C:\\DO.EXE " + args);
--> prints out badly, C:\DO.EXE "Ei mõõritelty"
message = "C:\\DO.EXE" + args;
PrintStream ps = new PrintStream(System.out, true, "Cp852");
--> prints out correctly, C:\DO.EXE "Ei määritelty"
Sun Java Supported Character Encodings
You might be right, I don't set a character encoding and maybe there are different defaults in sdk and in JRE,
this is the code that saves the file, can anyone tell me how to set the character Encoding ?
final Transformer t = TransformerFactory.newInstance().newTransformer();
OutputStream outputStream = new FileOutputStream(XmlFilePath);
t.transform(new DOMSource(document), new StreamResult(outputStream));
My problem was that before the code above, I converted byte to string without setting charset encoding.
return new String(buffer);
return new String(buffer,"UTF-8");