/**
* 使用缓冲流来边读边写
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
@SuppressWarnings("unused")
public class BufferedReaderTest {
public static void main(String[] args) throws IOException {
File file = new File("E:/java.txt");
FileInputStream fis = new FileInputStream(file);//把file输入到内存
InputStreamReader isr = new InputStreamReader(fis);//把字节流转换成字符流
BufferedReader br = new BufferedReader(isr);//从内存中把字符流读到缓冲流,
String temp;
while ((temp=br.readLine())!=null) {//缓冲流就像吸管一样,如果吸管满了,就会流入杯中,缓冲流满了,就会打印出来
System.out.println(temp);
}
br.close();
}
}
使用缓冲流在内存中读取字符流
最新推荐文章于 2021-07-25 16:12:52 发布