开发者

eclipse: Find Resource with a locationURI

开发者 https://www.devze.com 2023-01-12 09:39 出处:网络
How can i find a Resource with a locationURI? Path path = new Path(\'/home/foo/eclipse/runtime-EclipseApplication/someproj/B.txt\');

How can i find a Resource with a locationURI?

Path path = new Path('/home/foo/eclipse/runtime-EclipseApplication/someproj/B.txt');
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);

I know there is a way by using the locationURI from current pro开发者_开发百科ject to trim the "needless" part, but is there a "better" way to slove this issue.


You can use the following construction:

ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(URIUtil.toURI(fileName));

where fileName - absolute path of File.getAbsolutePath()

and URIUtil from org.eclipse.core.filesystem


You can use a FileLocator to find the file within your bundle, if that is what you want (instead of finding a file in the runtime workspace), see Retrieve a file from within a folder in the workspace

0

精彩评论

暂无评论...
验证码 换一张
取 消