我正在使用以下代码读取文本文件的前 6 行:
File finish = new File("C:/ABC Statements final/");
File[] finf = finish.listFiles();
String[] filenames1 = finish.list();
LineNumberReader br = null;
PrintWriter bw = null;
for (int k = 0; k < filenames1.length; k++) {
try {
br = new LineNumberReader(new FileReader(new File("C:/ABC Statements final/" + filenames1[k])));
String line = br.readLine();
while (line != null && br.getLineNumber() <= 6 ) {
line = br.readLine();
System.err.println(line);
}
} catch (Exception asd) {
System.err.println(asd);
}
我的输出不打印文件的第一行。谁知道我做错了什么?