从java的起始行到结束行读取一组文件记录的有效方法是什么。 我写了这个,但我认为它并不优雅:
protected void readPreferenceRecords(int start, int end) throws IOException{
InputStream input;
int i = 0;
LineNumberReader reader;
List lines;
String line;
lines = new ArrayList();
input = new FileInputStream(new File(posFile));
reader = new LineNumberReader(new InputStreamReader(input));
while (i < start) {
reader.readLine();
i++;
} if (i == start) {
while ((line = reader.readLine()) != null && (i <= end)){
lines.add(line);
i++;
}
}
for (String l : lines) {
System.out.println(l);
}
}