-3
我一直试图检查两行是否具有相同的内容,以便在完成所有操作时将其保留在文件之外。但是,检查两者是否相似的if语句无法正常工作。即使这些界限看起来很相似,if语句仍然认为它是错误的。为什么从一个文件中的这一行与具有相同字符的字符串不一样?
String fileLine = "";
String comp = "";
BufferedReader tempRead = new BufferedReader(new FileReader(new File("res/save.sav")));
PrintWriter tempWrite = new PrintWriter(new FileWriter(new File("res/tempSave.sav")));
for(String s: addToSave){
while((fileLine = tempRead.readLine()) != null){
comp = s.substring(0, s.length()-4);
System.out.print(fileLine.substring(0, comp.length()-1));
System.out.print(comp);
if(fileLine.substring(0, comp.length()-2).equals(comp)){
System.out.println("is gud");
}
}
}
tempWrite.close();
tempRead.close();
好吧,请记住,当你谈论电脑时,“看似相似”绝对是“不一样”。 – Craig
在另一个语句中,你有'fileLine.substring(0,comp.length() - 1)',在另一个语句中有'fileLine.substring(0,comp.length() - 2)'。这应该是什么? –