Escape result of FileLocator.resolve(url)

前端 未结 3 1907
孤独总比滥情好
孤独总比滥情好 2021-02-15 15:31

The method FileLocator.resolve(url) can be used to translate an address bundleentry://something/somewhere/x.txt to a proper file URL for /mnt/foo

3条回答
  •  伪装坚强ぢ
    2021-02-15 15:57

    Two additional notes:

    • FileLocator.resolve indeed resolves an URL, but it does not necessarily return a file:/ URL. In the default case where your bundle is packed (in a .jar), you should use FileLocator.toFileURL, which automatically extracts the resource to a cache if needed.
    • since Eclipse 4.x now includes EMF Common API by default, you can escape the URL more simply with EMF's URI API as follows:

    URI resolvedUri = URI.createFileURI(resolved.getPath());

    To get the file name, call resolvedUri.toFileString();

提交回复
热议问题