I have List of Paths, each path represents file with text lines - i.e. 10 lines in each file. My task is to read each first line from each file, then each second, each third and so on.
Trying to do this with BufferedReader so far results in it reading only first lines.
List<String> eachNLineFromEachFile = new ArrayList<>();
for (int i = 0; i < 10; i++) {
for (Path tempfile : tempFilesList) {
BufferedReader tempfileReader = Files.newBufferedReader(tempfile);
String line = null;
line = tempfileReader.readLine();
eachNLineFromEachFile.add(line);
try (BufferedWriter outputwriter = Files.newBufferedWriter(outputFile)) {
outputwriter.write(String.valueOf(eachNLineFromEachFile));
}
System.out.println(eachNLineFromEachFile);
}
}
So far it results with reading each first line of each file and then repeating with each first line.
How can get needed offset to work? I.e. each loop iteration to start reading from next line. AFAIK I should not use RandomAccessFile, which could probably do the trick with its getFilePointer and seek() methods).
Please help and thanks in advance.