import java.io.*;
public class CheckingTwoFilesAndComparing implements Serializable {
private static final long serialVersionUID = 1L;
static String FILE_ONE = "/Users/abextra/myText1.txt";
static String FILE_TWO = "/Users/abextra/myText2.txt";
public static void main(String[] args) {
try {
CompareFile(FILE_ONE, FILE_TWO);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void CompareFile(String fILE_ONE2, String fILE_TWO2)
throws Exception {
File f1 = new File("FILE_ONE");
File f2 = new File("FILE_TWO");
FileReader fR1 = new FileReader(f1);
FileReader fR2 = new FileReader(f2);
BufferedReader reader1 = new BufferedReader(fR1);
BufferedReader reader2 = new BufferedReader(fR2);
String line1 = null;
String line2 = null;
while (((line1 = reader1.readLine()) != null)
&&((line2 = reader2.readLine()) != null)) {
if (!line1.equalsIgnoreCase(line2)) {
System.out.println("The files are DIFFERENT");
} else {
System.out.println("The files are identical");
}
}
reader1.close();
reader2.close();
}
}
这是上面代码中提到的路径中存在的2个文本文件的内容
==myText1.txt===
1,This is first line, file
2,This is second line, file
3,This is third line , file
4,This is fourth line, file
==myText2.txt===
1,This is first line, file
2,This is second line, file
3,This is third line, file
4,This is fourth line, file
5,This is fifth line, file
我是 java 的新手。我使用了 eclipse 调试器,我看到我不断收到“FileNot found”异常 - 有人可以帮忙吗?非常感谢!