FileInputStream fr = new FileInputStream(path);
InputStreamReader is = new InputStreamReader(fr,"UTF-8");
BufferedReader br=new BufferedReader(is);
FileOutputStream stream;// provides file access
OutputStreamWriter writer;// writes to the file
try {
stream = new FileOutputStream(filename);
writer = new OutputStreamWriter(stream,"UTF-8");
在用java写文件的时候我们往往利用这种方式:
BufferedWriter output = new BufferedWriter(new FileWriter(new File("filepath")));
但是利用这种情况写的文件编码格式默认是当前操作系统的编码格式,
如果想设置为您所需要的格式现在可以利用这种方法:
OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream("filepath"),"UTF-8");这样就可以设置为你所需要的格式了,具体的原理稍后补上。 |