-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)'。這應該是什麼? –