문제

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