public class ReadFileByLines {
public static void main(String[] args) {
try{
//1.打开一个file
File file = new File("E:/test.txt");
//2.InputStreamReader<-FileInputStream<-file
FileInputStream fis = new FileInputStream(file);
InputStreamReader is = new InputStreamReader(fis);
//3.用BufferedReader(<-InputStreamReader)的readLine()方法读取
BufferedReader br = new BufferedReader(is);
//4.输出
String txtLine = null;
while((txtLine=br.readLine())!=null){
System.out.println(txtLine);
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
}
}