标签:ccf 文本 bool 打开 str fileinput [] input 字节
Reader/Writer(字符流)
//能够用文本编辑器打开的文件,不乱码就是字符文件
//用文本编辑器打开的文件,出现乱码的,就是字节文件
1.FileReader
int b = fr.read(); //写一个字符
2.FileWriter
fw.writer(char); //写一个字符
fw.writer(char[]); //写字符数组
3.BufferedReader(字符输入缓冲流)
BufferedReader br = new BufferedReader(new FileReader("文件路径"));
String str = br.readLine(); //读取一行字符
4.BufferedWriter(字符输出缓冲流)
BufferedWriter bw = new BufferedWriter(new FileWriter("文件路径"));
bw.writer(字符串);
小结:
1.读写字符文件
BufferedReader br = new BufferedReader(new FileReader(文件));
BufferedWriter bw = new BufferedWriter(new FileWriter(文件,boolean));
2.读写字节文件
DataInputStream dis = new DataInputStream(new FileInputStream(文件));
DataOutputStream dos = new DataOutputStream(new FileOutputStream(文件));
3.读取整个字符文件
String str = null;
while( (str=br.readLine()) != null){
System.out.println(str);
}
4.读取整个字节文件
int b;
while( (b=dis.read()) !=-1){
System.out.println(b);
}
标签:ccf 文本 bool 打开 str fileinput [] input 字节
原文地址:http://www.cnblogs.com/xykwh/p/6835132.html