我正在比较两个文本文件:
newfile.txt
的内容为JAVA
newtextfile
的内容为JAVA
但是我仍然得到文件不相同的信息,请帮助我解决问题。
public class BufferReaderprogram {
public static void main(String[] args) throws IOException {
File f=new File("F:\\text\\newfile.txt");
File f1=new File("F:\\text\\newtextfile.txt");
FileWriter fileWriter = new FileWriter(f1);
fileWriter.write("JAVA");
fileWriter.flush();
fileWriter.close();
FileReader newfile = new FileReader(f);
BufferedReader bufferedReader = new BufferedReader(newfile);
FileReader newtextfile = new FileReader(f1);
BufferedReader bufferedReader1 = new BufferedReader(newtextfile);
String line1=bufferedReader.readLine();
String line2=bufferedReader1.readLine();
boolean flag=true;
if(line1==null || line2==null){
System.out.println(line1);
System.out.println(line2);
System.out.println("Files is empty");
}
else{
while(line1!=null && line2!=null){
System.out.println(line1);
System.out.println(line2);
if(! line1.equalsIgnoreCase(line2)){
System.out.println("Files are not same");
flag=false;
break;
}
}
if(flag){
System.out.println("Files are same");
}
}
}
}
我用if(! line1.equalsIgnoreCase(line2))
检查了两个文件的内容,我在这里做错了吗?