import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BufferReader {
public static void main(String[] args){
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("src/test.txt")); //相对文件路径,如果是放在项目文件夹下,则为new FileReader("test.txt");
String string;
while ((string=bufferedReader.readLine()) != null){
System.out.println(string);
}
System.out.println(string);
} catch (IOException e) {
e.printStackTrace();
}
}
}
目录关系
运行效果