在开始写入之前,可以使用RandomAccessFile来使用方法来
查找 光标并将其
0th定位
seek(long position)。
如本主题所述
RandomAccessFile f = new RandomAccessFile(new File("yourFile.txt"), "rw");f.seek(0); // to the beginningf.write("Jennifer".getBytes());f.close();编辑: 正如下面许多评论所指出的,此解决方案从一开始就 覆盖 了文件内容。要完全替换内容,可能必须 删除 并 重写 File 。



