環境:Windows、Java 1.8 ファイルの内容を読み込んでいますが、行の書式を設定してタブを削除しようとしましたが、replaceAll
は機能しません。文字列からタブが削除されない
私がしようと試み:私はデバッガに見て、タブが置き換えられない
BufferedReader bf = FileUtils.getBufferedReader(filePath);
String line;
try {
while ((line = bf.readLine()) != null)
{
if(line.matches(".*=.*"))
{
// this is a simple test scenario
String test = "\tVERSION=version";
test.trim();
test.replaceAll("\t", "");
line.trim();
line.replaceAll("\\t", "");
}
}
} catch (IOException e) {
System.err.println("[ERROR] : Could not read from file <" + filePath + ">!\n");
System.exit(0);
}
。テストシナリオでは、私は\t
と\\t
の両方の変種を試してみました。私は何か間違っているのですか?
「文字列」を再割り当てする方法は、「文字列」は不変です。 – SomeJavaGuy
'' test = test.replaceAll(...) 'など、いくつかのJavaの男が提案したようにしてください) – Thomas
@SomeJavaGuyうん、それは問題だった –