I try to write chinese character but take a wrong result
For Instance :
import java.io.*;
import java.nio.*;
class x {
public static void main(String... args) throws Exception {
OutputStreamWriter outputStreamWriter =
new OutputStreamWriter(new FileOutputStream(new File("practice.csv"), true), "GBK");
outputStreamWriter.write("常用场景");
outputStreamWriter.write("Helo World!");
outputStreamWriter.flush();
outputStreamWriter.close();
}
}
Response : ????¡±¡§??????Helo World!
I tried to change charset utf-8, utf-16 but it doesn't anything and lastly I tried to add BufferedWriter but unfortunately it doesn't anything again.
then I considered to change csv to txt, but again same result. What am I doing wrong ?
CodePudding user response:
I found it finally. Firstly very thanks for helping @Kayaman and @user16320675.
In fact, everything was correct. This problem's resource is csv files is opened by excel. When you want to open csv files directly in excel, it opens according to the encoding of the current computer language. We just have a option in Windows 10 EN(manually Data Import). I used the windows 10 EN and excel uses ANSI for windows 10 EN.
My Solution : I added to chinese language pack to my windows 10 computer and I changed the excel editing language (chinese for default) and everything worked.