Java:
文件内容:RandomAccessFile raf = new RandomAccessFile("C:\\1.txt", "rw"); String s = raf.readLine(); long pointer =0; while(s!=null) { System.out.println(s); if(s.contains("py")) { raf.seek(pointer); raf.writeBytes("hello python"); } pointer = raf.getFilePointer(); s = raf.readLine(); }
hello world
hello c++