Plug-in with file(s) [message #289390] |
Thu, 04 August 2005 11:08 |
Eclipse User |
|
|
|
Originally posted by: callum.devnet-uk.net
My plug-in gets some data (just plain ascii chars) from a file. I have a
added these the build path and when I run I can read the file contents
like this:
URL url = Platform.getBundle ("BundleName").getEntry ("path to file") ;
InputStream in = url.openStream() ;
int i ;
while ((i =in.read()) != -1)
System.out.print ((char)i) ;
if (in !=null) in.close () ;
Now, this is "ok", but is there a more friendly way of this doing, such as
grabbing a line at a time?
I tried to use other stream classes, such a FileReader, etc but when
trying to open the file it always says it can't find it. Am I stuck with
this method?
|
|
|
Re: Plug-in with file(s) [message #289394 is a reply to message #289390] |
Thu, 04 August 2005 11:45 |
|
Callum Urquhart wrote:
>
> My plug-in gets some data (just plain ascii chars) from a file. I have a
> added these the build path and when I run I can read the file contents
> like this:
>
> URL url = Platform.getBundle ("BundleName").getEntry ("path to file") ;
>
> InputStream in = url.openStream() ;
> int i ;
> while ((i =in.read()) != -1)
> System.out.print ((char)i) ;
>
> if (in !=null) in.close () ;
>
> Now, this is "ok", but is there a more friendly way of this doing, such
> as grabbing a line at a time?
>
> I tried to use other stream classes, such a FileReader, etc but when
> trying to open the file it always says it can't find it. Am I stuck with
> this method?
You just need to wrap your InputStream in a bridge:
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine())!=null) {
....
}
Later,
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
|
Powered by
FUDForum. Page generated in 0.03513 seconds