缓冲区字符流,读取根目录下的hello.txt文件内容(更简单方便的读取每一行)

时间:2021-09-25 21:00:16
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 	缓冲区字符流,读取根目录下的hello.txt文件内容(更简单方便的读取每一行)
 */
public class BufferReaderDemo {
	public static void main(String[] args) {
		try {

			BufferedReader br = new BufferedReader(new FileReader("test.txt"));
			// 打印 文件,输出每一行
			String line;
			while ((line = br.readLine()) != null) {

				System.out.println(line);
			}

			br.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}