使用IFile::setContents()更改文件的内容。
要清除文件内容,请使用空输入流:
代码语言:javascript运行复制InputStream newContents = new ByteArrayInputStream( new byte[ 0 ] );
IProgressmonitor monitor = ...
file.setContents( newContents, IResource.KEEP_HISTORY, monitor );KEEP_HISTORY标志将以前的内容保留在历史中,以便用户可以使用Replace with > Local History返回到较早的版本。如果这不是我们想要的,可以使用IResource.NONE。