public
static
void
main(String[] args)
throws
IOException {
long
timeStart = System.currentTimeMillis();
File file =
new
File(
"testData.txt"
);
//文件路径
FileReader fileReader =
new
FileReader(file);
LineNumberReader reader =
new
LineNumberReader(fileReader);
int
number =
99
;
//设置指定行数
String txt =
""
;
int
lines =
0
;
while
(txt !=
null
) {
lines++;
txt = reader.readLine();
if
(lines == number) {
System.out.println(
"第"
+ reader.getLineNumber() +
"的内容是:"
+ txt +
"\n"
);
long
timeEnd = System.currentTimeMillis();
System.out.println(
"总共花费:"
+ (timeEnd - timeStart) +
"ms"
);
System.exit(
0
);
}
}
reader.close();
fileReader.close();
}
}