Reputation: 140
What is the better approach to get an absolute path on the local file system from an IResource?
IResource res;
...
res.getLocation().makeAbsolute().toString();
or
IResource res;
...
new File(res.getLocationURI()).getAbsolutePath();
(I skipped null checks in this example.)
Upvotes: 0
Views: 81
Reputation: 111141
Probably:
res.getLocation().toOSString();
The location should always be absolute so no need to call makeAbsolute
(although it will not cost much when the path is already absolute).
Use toOSString()
to get the path in the format used by the OS (so \ on Windows, / on Mac, Linux).
You can also use toPortableString()
to get a standard format path which is useful for data interchange but is not suitable for use with File
.
Upvotes: 1