本帖最后由 吴硕 于 2012-11-1 17:31 编辑
- import java.io.*;
- class FileWriterDemo
- {
- public static void main(String[] args) throws IOException
- {
- FileWriter fw = new FileWriter("r:/demo.txt"); //1
- fw.write("你好");
- fw.close();
- }
- }
复制代码 同样是写入文件,为什么转换流可以指定字符编码,而FileWriter流却不可以在1处指定字符编码
转换流可以- import java.io.*;
- class Demo
- {
- public static void main(String[] args) throws IOException
- {
- OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("demo.txt"), "utf-8");
- osw.write("你好");
- osw.close();
- }
- }
复制代码 |