package rxxj;
import java.io.*;
public class Life {
public static void main(String[] args) {
String fileName = "D:/all/demo/day/src/rxxj/text.txt";
readFileByLines(fileName);
}
public static void readFileByLines(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {//返回读取的该行的字符串,为null表示读完
System.out.println(tempString);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}
执行结果