1
I have two different.txt files as an example: arquivo1.txt has 1854 lines with 6 numbers on each line separated by " "(a space). In the other file 2.txt I have more than 1 million lines with 6 numbers on each line separated by " "(a space too). I tried to get the first line of the archive2.txt to analyze all the lines of the archive1.txt by looking for how many equal numbers there are in each line of the archive1.txt and then go to the next line of the archive2.txt and again do the same analysis that was done before, by the end of archive2.txt. But the problem is that my code is only analyzing the first line of the file1.txt with the first line of the file2.txt, then jumps to the next line of both files. Someone can help me write this code the way I’d like. The code is as follows::
public class Confere {
public static void main(String[] args) throws FileNotFoundException {
try {
// pega os arquivos txt´s
File file = new File("C:/Users/Usuario/Documents/Vander/mega.txt");
File file2 = new File("C:/Users/Usuario/Documents/Vander/resultadomega.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
FileReader fileReader2 = new FileReader(file2);
BufferedReader bufferedReader2 = new BufferedReader(fileReader2);
while (bufferedReader.ready()) {
bufferedReader2.ready();
String linha = bufferedReader.readLine(); // lê uma linha...
String linha2 = bufferedReader2.readLine(); // lê uma linha...
if (linha.toString().contains(linha2.toString())) { // verifica se as linhas são iguais
System.out.println("igual");
// #####################################################
RandomAccessFile raf = new RandomAccessFile("C:/Users/Usuario/Documents/Vander/relatorio.txt", "rw");
raf.seek(raf.length());
raf.writeBytes(linha + "\r\n");
raf.close();
// ######################################################
System.out.println(linha);
} else {
System.out.println("diferente");
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
I’d be very grateful, because it’s very difficult...
In short... You want to count the occurrences of each line of the file 1.txt in the file 2.txt?
– rodorgas
That would be, showing the line of the file 2.txt and how many occurrences they had in each line, for example: line 1 = 4 occurrences and so on until the end of the file 2.txt.
– Vandão