Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Using java.nio.file with Eclipse URL ?
Using java.nio.file with Eclipse URL ? [message #1455548] Wed, 29 October 2014 13:32 Go to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
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.

Anybody a hint on this ?

Thomas Elskens
Re: Using java.nio.file with Eclipse URL ? [message #1455635 is a reply to message #1455548] Wed, 29 October 2014 15:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:RCP issues (view titles, toolbar, quick access)
Next Topic:KeyBindings & KeysPreferencePage
Goto Forum:
  


Current Time: Wed Jan 27 14:59:08 GMT 2021

Powered by FUDForum. Page generated in 0.03919 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top