create file支持UTF-8

时间:2012-04-09 13:01:06

标签: java file csv utf-8

  

可能重复:
  How to write a UTF-8 file with Java?

我想使用java创建一个csv文件并写入支持UTF-8的文件。 我怎么能这样做??

2 个答案:

答案 0 :(得分:5)

new OutputStreamWriter(new FileOutputStream("path/to/file"), Charset.forName("UTF-8"))

答案 1 :(得分:1)

Writer myWriter= new BufferedWriter(new OutputStreamWriter(
    new FileOutputStream("filename"), "UTF-8"));
try {
    myWriter.write(stringdata);
} catch(Exception e){
e.printStacktrace();
}