package demo.test2;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
public class BufferReaderDemoAll {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
p1();
}
/**
* BufferedReader 读取文件内容
* 通常我们会用readLine()一次一次的读取输入,需要将文件包装成bufferedReader来使用,这要求我们必须使用InputStreamReader把文件转成Reader
* BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("a.txt"), "utf-8"));
*
* @throws IOException
*/
public static void p1() throws IOException{
FileInputStream fis = new FileInputStream("a11.txt");
//第一个参数指定FileInputStream,第二个参数指定 字符集
InputStreamReader isr = new InputStreamReader(fis, "utf-8");
BufferedReader bf = new BufferedReader(isr);
String len = null;
while((len = bf.readLine()) != null){
System.out.println(len);
}
bf.close();
}
}
file操作(7)--------------- BufferedReader读取文件内容
最新推荐文章于 2022-08-01 17:58:37 发布