Question

I'm trying to create a file using the Cp1250 charset:

out = new BufferedWriter(
        new OutputStreamWriter(
        new FileOutputStream("/path/filename"), Charset.forName("Cp1250")));

However, when I detect the actual charset with juniversalchardet, it says WINDOWS-1252 which is Cp1252 (according to javadoc).

Enca (enca -L czech -g filename) detects ISO-8859-2.

How could I set exactly Cp1250 (or, using java.nio API name, windows-1250)?

Thank you

Karel

Was it helpful?

Solution

Any encoding detection program can only be heuristic when it comes to encodings which are basically valid for all files (e.g. ones which are always one byte per character and have a character mapped to every byte).

You should encode some text which you know would cause different results between Windows-1250 and Windows-1252, and see what your code actually does. I suspect you'll find it's actually doing the right thing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top