标签:字符编码 关于 cat string 读写 图片 ati 默认 img
package com.zyb.pric;
import java.io.*;
public class FileOperate {
public static void main(String[] args) {
writeFile();
readFile();
}
public static void writeFile(){
FileOutputStream fos=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String charSet="utf-8";//写入的字符编码
try {
fos=new FileOutputStream("d:/test.txt");//节点类
osw= new OutputStreamWriter(fos,charSet);//转化类
bw=new BufferedWriter(osw);//装饰类
bw.write("我是");
bw.newLine();
bw.write("hututu");
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void readFile(){
FileInputStream fis=null;
InputStreamReader isr=null;
BufferedReader br=null;
String charSet="GB2312";//写入的字符编码
try {
fis=new FileInputStream("d:/test.txt");//节点类
isr=new InputStreamReader(fis,charSet);//转化类
//isr=new InputStreamReader(fis);采用系统默认编码
br=new BufferedReader(isr);//装饰类
String line;
while((line=br.readLine())!=null){
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
标签:字符编码 关于 cat string 读写 图片 ati 默认 img
原文地址:https://www.cnblogs.com/cstdio1/p/12233154.html