一种方法是使用
String.replaceAll():
File log= new File("log.txt");String search = "textFiles/a\.txt"; // <- changed to work with String.replaceAll()String replacement = "something/bob.txt";//file readingFileReader fr = new FileReader(log);String s;try { BufferedReader br = new BufferedReader(fr); while ((s = br.readLine()) != null) { s.replaceAll(search, replacement); // do something with the resulting line }}您还可以使用正则表达式,或
String.indexOf()查找搜索字符串在一行中的何处。



