Frage

I want to write some special characters from UTF-16 to a file. I tried some methods but I don't get what is going on behind scenes. Below code writes 'u' character to file. How can I write special charaters from UTF-16?

    File f = new File("test");
    FileOutputStream fos = new FileOutputStream(f);
    OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-16");
    fos.write(16757);
War es hilfreich?

Lösung

You would have to use write() of OutputStreamWriter to write the encoded chars:

Change:

fos.write(16757);

To:

osw.write(16757);

Andere Tipps

try maybe something like this:

    File f = new File("test");
    FileOutputStream fos = new FileOutputStream(f);
    fos.write("16757").getBytes("UTF-16"));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top