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

问题描述 投票:0回答:1

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

一个

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);
eclipse eclipse-plugin rcp
1个回答
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'更适合单个文件。

© www.soinside.com 2019 - 2024. All rights reserved.