我有一个包含 10 行的 txt 文件,我想编写 Java 代码来显示第 3 行到第 5 行。
有人可以帮助我吗?
最佳答案
void Scan(String filename, int start, int end) {
Scanner in = null;
try {
in = new Scanner(new File(filename));
} catch(FileNotFoundException e) {
e.printStackTrace();
}
int line = 1;
while(line < start) {
in.nextLine();
line++;
}
while(line <= end) {
System.out.println(in.nextLine());
line++;
}
}
}
关于java - 在java中显示文件中的一些行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153496/