如何删除文本文件的内容,但不删除自己但不、文本文件、内容

2023-09-12 07:08:00 作者:讨厌鬼

我要复制文件'A'的内容文件'B'。 复制完成后,我要清除的文件A的内容,并希望写在从它开始的文件'A'。 我无法删除文件'A',因为它是与其他一些任务连接。

I want to copy the content of file 'A' to file 'B'. after copying done I want to clear the content of file 'A' and want write on file 'A' from its beginning . I can't delete the file 'A' as it is connected with some other task.

我可以使用Java的文件API(的readLine())复制的内容,但不知道如何清除文件的内容和文件指针设置为文件的开头。

I was able to copy the content using java's file API(readLine() ), but don't know how to clear the content of file and set the file pointer to beginning of the file.

推荐答案

只是打印一个空字符串到文件:

Just print an empty string into the file:

PrintWriter writer = new PrintWriter(file);
writer.print("");
writer.close();
 
精彩推荐
图片推荐