研究下FileWriter和FileOutputStream的区别!!
FileWriter是按照本地平台的字符编码来写数据.是OutputStreamWriter的直接子类,是属于字符输出流.
FileOutputStream是OutputStream的直接子类,是字节输出流.
我往文件里写字符串用的PrintWriter 格式化字符输出流 作为装饰器, 用OutputStreamWriter把FileOutputStream转化成Writer....FileWriter我没用过.
public void write(File f,String str,String charsetName){
try{
PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream(f),charsetName));
writer.println(str);
writer.close();
}
catch(IOException e){throw new RuntimeException(e);}