我必须验证文件1中的单词1与文件2中的单词2的相似性,依此类推.如果单词1(文件1).equals到单词2(文件2),则文件3将是输出以显示True和False.下面是编码,但是当没有错误但没有输出时我被卡住了.我是JAVA的初学者.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class test2 {
private static ArrayList load(String f1) throws FileNotFoundException {
Scanner reader = new Scanner(new File(f1));
ArrayList out = new ArrayList();
while (reader.hasNext()) {
String temp = reader.nextLine();
String[] sts = temp.split(" ");
for (int i = 0; i < sts.length; i++) {
if (sts[i].equals("") && sts[i].equals(" ") && sts[i].equals("\n")) {
out.add(sts[i]);
}
}
}
return out;
}
private static void write(ArrayList out, String fname) throws IOException {
FileWriter writer = new FileWriter(new File("out_test2.txt"));
for (int i = 0; i < out.size(); i++) {
writer.write(out.get(i) + "\n");
}
writer.close();
}
public static void main(String[] args) throws IOException {
ArrayList file1;
ArrayList file2;
ArrayList out = new ArrayList();
file1 = load("IbanDict.txt");
file2 = load("AFF_outVal.txt");
for (int i = 0; i < file1.size(); i++) {
String word1 = file1.get(i);
for (int z = 0; z < file2.size(); z++) {
if (word1.equalsIgnoreCase(file2.get(z))) {
boolean already = false;
for (int q = 0; q < out.size(); q++) {
if (out.get(q).equalsIgnoreCase(file1.get(i))) {
already = true;
}
}
if (already == false) {
out.add(file1.get(i));
}
}
}
}
write(out, "out_test2.txt");
}
}