refreshLocal的原型为:
public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException;
refreshLocal方法可以传递一个尝试参数,以指明刷新的对象仅仅是该资源,还是该资源及其成员,或者是该资源及其所有后代资源。所有由工作空间api引起的更改,例如向项目中添加文件夹或文件,都会立即反映到内存中的工作空间资源模型。在工作空间中创建一个新的资源,也会相应地存在于文件系统中。直接对文件系统进行的更改,例如使用命令行或操作系统用户界面将文件夹或文件复制到项目中,并不会被工作空间所感知,直到用户或者由工作空间API(IResource.refreshLocal)执行一次刷新操作,这些更改才会反映到工作空间中。如果需要的话,用户可以让刷新操作自动执行。
看看源码中的更新深度(int depth):
/**
* Depth constant (value 0) indicating this resource, but not any of its members.
* 此深度常量代表资源本身
*/
public static final int DEPTH_ZERO = 0;
/**
* Depth constant (value 1) indicating this resource and its direct members.
* 此深度常量代表资源本身和其直接资源
*/
public static final int DEPTH_ONE = 1;
/**
* Depth constant (value 2) indicating this resource and its direct and
* indirect members at any depth.
* 此深度常量代表资源本身和其直接或间接成员
*/
public static final int DEPTH_INFINITE = 2;
另外需要注意的是:
如果直接通过java.io流改写文件,假若流没有关闭,此时,即使使用了同步(refreshLocal),也会报同步失败(out of syn file system)。关闭掉流,就好了。