我怎么能以编程方式刷新项目?接近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);
尽可能使用
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'更适合单个文件。