У меня есть 2 текстовых файла на двух разных языках, и они выровнены построчно. т.е. первая строка в текстовом файле1 должна быть равна первой строке в текстовом файле2, и так далее, и тому подобное.
Есть ли способ читать оба файла построчно одновременно?
Ниже приведен пример того, как должны выглядеть файлы, представьте, что количество строк в файле составляет около 1 000 000.
текстовый файл1:
This is a the first line in English
This is a the 2nd line in English
This is a the third line in English
текстовый файл2:
C'est la première ligne en Français
C'est la deuxième ligne en Français
C'est la troisième ligne en Français
желаемый результат
This is a the first line in English\tC'est la première ligne en Français
This is a the 2nd line in English\tC'est la deuxième ligne en Français
This is a the third line in English\tC'est la troisième ligne en Français
В настоящее время я могу использовать это, но сохранение нескольких миллионов строк в ОЗУ убьет мою машину.
String english = "/home/path-to-file/english";
String french = "/home/path-to-file/french";
BufferedReader enBr = new BufferedReader(new FileReader(english));
BufferedReader frBr = new BufferedReader(new FileReader(french));
ArrayList<String> enFile = new ArrayList<String>();
while ((line = enBr.readLine()) != null) {
enFile.add(line);
}
int index = 0;
while ((line = frBr.readLine()) != null) {
String enSentence = enFile.get(index);
System.out.println(line + "\t" + enSentence);
index++;
}