There are questions like this, that are about guessing charset/encode of a file. But is there a method in Java to ask the system to tell me before try to guess?
so, if I write a file with the esplicit encoding, than I have to remember, or guess, the encoding when I have to read it again?
s.susini
2010-09-20 12:26:01
@s.susini: if you use a "plain text" file, yes. Which is why that's not such a great file format. Say what you want about XML, but its explicit encoding declaration can save you a lot of headaches.
Michael Borgwardt
2010-09-20 12:27:56
That's correct. Just be consistent with the encoding. UTF-8 is a good choice.
BalusC
2010-09-20 12:28:12
+6
A:
How is "the system" supposed to know? If the encoding isn't declared in some sort of metadata somewhere, then educated guessing is the only thing that can be done.
Michael Borgwardt
2010-09-20 12:12:13
As you wrote, it could be declared in some sort of metadata somewhere... such as the extended attributes on MacOS X. So, one could imagine that other systems use similar mechanisms to keep track of text encoding, and that a Java method would provide a unified way to access these mechanisms. No such luck, though :-/
Damien
2010-09-20 12:54:53
+1
A:
There is no way for the system to know what encoding was used when the file was written. The system would need to try make an educated guess based on the file contents, same as you would do yourself from your application.
You will need to implement this yourself, or use an external library such as the ones described in the original question you referenced.
Grodriguez
2010-09-20 13:48:13