Boa tarde, estou tentando comparar dois arquivos txt, mas ele me apresenta o valor do 1 arquivo e nao a comparaçao entre os dois… Alguém sabe me ajudar???
[code]import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
class Main {
static String linha;
static String linha2;
public static double jaccardSimilarity(String similar1, String similar2) {
HashSet<String> h1 = new HashSet<String>();
HashSet<String> h2 = new HashSet<String>();
for (String s : similar1.split("\\s+")) {
h1.add(s);
}
System.out.println("h1 " + h1);
for (String s : similar2.split("\\s+")) {
h2.add(s);
}
System.out.println("h2 " + h2);
int sizeh1 = h1.size();
// Pega todos os elementos
h1.retainAll(h2);
// h1 contem intersecçao de h1 e h2
System.out.println("Intersection " + h1);
h2.removeAll(h1);
// h2 contem elementos unicos
System.out.println("Unique in h2 " + h2);
// Uniao
int union = sizeh1 + h2.size();
int intersection = h1.size();
return (double) intersection / union;
}
public static void main(String args[]) throws IOException {
Scanner ler = new Scanner(System.in);
Scanner ler2 = new Scanner(System.in);
System.out.printf("Informe o nome de arquivo1 texto:\n");
String nome = ler.nextLine();
System.out.printf("Informe o nome de arquivo2 texto:\n");
String nome2 = ler2.nextLine();
System.out.printf("\nConteúdo do arquivo texto:\n");
try {
FileReader arq = new FileReader(nome);
BufferedReader lerArq = new BufferedReader(arq);
linha = lerArq.readLine();
while (linha != null) {
System.out.printf("%s\n", linha);
String linhaa = lerArq.readLine();
linha = linhaa;
}
arq.close();
System.out.printf("Linha completa: " + linha);
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo: %s.\n",
e.getMessage());
}
// System.out.println(jaccardSimilarity(linha, linha2));
}
}
[/code]
BRIGADA, Veronica