日期:2014-05-20 浏览次数:20752 次
BufferedReader br = new BufferedReader(new FileReader("test.txt")); PrintStream ps = new PrintStream(new FileOutputStream("test.txt.new")); String buf; int count = 0; while ((buf=br.readLine()) != null) { count++; if (count == 4) { buf = buf.replaceAll("xxx", "yyy"); } ps.println(buf); } br.close(); ps.close(); File f1 = new File("test.txt"); f1.delete(); File f2 = new File("test.txt.new"); f2.renameTo(f1);