public static void main(String[] args) {
String path = "C:\\9cf9bee9b0a462da37addd305069be74_9c937250417cb8d1a4a1c91a3a53754d_8\\2018 01 10 0000 (String).DAT";
readFileByLines(path);
}
public static void readFileByLines(String fileName) {
//File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
//reader = new BufferedReader(new FileReader(file));
reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"GBK"));
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
// String str = new String(tempString.getBytes(), "ISO-8859-2");
System.out.println("line " + line + ": " + tempString);
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
02-13
3302
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)