|
Re: Using java.nio.file with Eclipse URL ? [message #1455635 is a reply to message #1455548] |
Wed, 29 October 2014 15:32  |
Ed Merks Messages: 31714 Registered: July 2009 |
Senior Member |
|
|
Thomas,
Comments below.
On 29/10/2014 2:32 PM, Thomas Elskens wrote:
> Hello,
>
> If I'm not mistaken, the standard way of reading a string from a file
> in RCP goes like this :
>
> InputStream is = new URL("path_to_file").openStream() ;
> BufferedReader reader = new BufferedReader(new InputStreamReader(is));
> String result = reader.lines().collect(Collectors.joining()) ;
>
>
> I would like to be able to use the library java.nio.file to read a
> string from a file in a much more concise fashion, a bit like this:
>
> String result =
> Files.lines(Paths.get("path_to_file")).collect(Collectors.joining()) ;
>
> In Eclipse however, all acces to resources is done with URL beginning
> with "platform:/plugin/" etc. I've tried all the methods toPath(),
> toUri()... I could find, but found nothing to convert my Eclipse URL
> into a valid java.nio.file.Path implementation.
org.eclipse.core.runtime.FileLocator.resolve(URL) might help, but it's
important to realize that the resource might be something within a jar
so the URL is a jar: URL and then it's not ideal to try to access it in
a way that expects it to be just a file system file.
> Anybody a hint on this ?
>
> Thomas Elskens
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03919 seconds