質問

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);
役に立ちましたか?

解決

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

Change:

fos.write(16757);

To:

osw.write(16757);

他のヒント

try maybe something like this:

    File f = new File("test");
    FileOutputStream fos = new FileOutputStream(f);
    fos.write("16757").getBytes("UTF-16"));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top