如何以编程方式刷新eclipse项目?

时间:2018-01-24 10:12:47

标签: eclipse eclipse-plugin rcp

我如何以编程方式刷新项目?接近A或B?顺便说一下,我的项目没有被复制到eclipse workspace.will会影响刷新项目的方式吗?

A

project.refreshLocal(IResource.DEPTH_INFINITE, new  org.eclipse.core.runtime.NullProgressMonitor());

java.io.File file = iFile.getLocation().toFile();
FileOutputStream fOut = new FileOutputStream(file);
fOut.write("Written by FileOutputStream".getBytes());          
iFile.refreshLocal(IResource.DEPTH_ZERO, null);

1 个答案:

答案 0 :(得分:0)

尽可能使用

iFile.setContents(stream, false, true, progressMonitor);

其中stream是包含内容的InputStream(例如,ByteArrayInputStream来写一个字符串)。注意字符串的字符集 - 它应该与分配给文件的字符集匹配,所以:

String string = "Written by FileOutputStream";
byte [] bytes = string.getBytes(iFile.getCharset());
InputStream stream = new ByteArrayInputStream(bytes); 

为第三个参数指定true告诉Eclipse维护该文件的本地历史记录。如果您不想要,请指定false

您的方法' A'刷新可能需要更多时间的整个项目,' B'最适合单个文件。

相关问题