我正在尝试用另一个子字符串替换文本文件中的子字符串。当我使用replace
时/replaceAll
我发现文件中没有看到更改。
temp = line.split("\"");
String str = temp[1].substring((temp[1].length())-4);
line = line.replace(str,"rvro");
当我打印替换前后的行时,它工作正常,但在主文件中看不到更改
我想使用一个文件来处理所有内容并在其上写入更改。
最佳答案
When I print the line before and after replacement,its working fine but the changes are not seen in the main file
您需要将字符串写回到文件中,也许使用 FileWriter .
关于java - 替换同一文本文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18477275/