2017-03-13 13 views
-3

私は2つの行が同じ内容を持っているかどうかをチェックしているので、すべてが終わってファイルが消えないようにしておきます。しかし、2つが似ているかどうかを調べるif文は、正しく動作していません。線は一見似ていますが、if文はそれを偽と見なします。あなたは1本の長さ、comp.length() - 2の文字列を持っていることはありませんファイルからのこの行が、同じ文字の文字列と同じではないのはなぜですか?

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(); 
+0

あなたがコンピュータについて話しているとき、「一見似ている」というのは間違いなく「同じではない」ことを覚えておいてください。 – Craig

+0

あなたは 'fileLine.substring(0、comp.length() - 1)'を持っています。それはどっちだろう? –

答えて

0

、長さの異なる別の文字列、comp.length()と等しくなります。

関連する問題