You would have to use write()
of OutputStreamWriter
to write the encoded chars:
Change:
fos.write(16757);
To:
osw.write(16757);
Pergunta
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);
Solução
You would have to use write()
of OutputStreamWriter
to write the encoded chars:
Change:
fos.write(16757);
To:
osw.write(16757);
Outras dicas
try maybe something like this:
File f = new File("test");
FileOutputStream fos = new FileOutputStream(f);
fos.write("16757").getBytes("UTF-16"));