[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
AW: [platform-core-dev] Getting the input stream for a resource- can't be that difficult!
|
Tom,
I did not try the URL returned by Platform.find() directly because it contains a bundleentry: protocol specifier and I did not expect that a standard java.net.URL can make anything out of that.
But to my surprise it does work which means that I do not know enough about how an URL resolves it's path in general and in the eclipse context.
Thanks for your advice
Norbert
________________________________
Von: platform-core-dev-bounces@xxxxxxxxxxx [mailto:platform-core-dev-bounces@xxxxxxxxxxx] Im Auftrag von Thomas Watson
Gesendet: Mittwoch, 27. April 2005 15:39
An: Eclipse Platform Core component developers list.
Betreff: Re: [platform-core-dev] Getting the input stream for a resource- can't be that difficult!
Peter's suggestion will only work if you have "." on the Bundle-ClassPath. You can also try:
Bundle b = Platform.getBundle(PLUGIN_NAME);
URL url = Platform.find(b, new Path(path));
InputStream is = null;
if (url != null)
is = url.openStream();
Did the url from Platform#find not work unless you resolved it? Questions like this should be posted to the news groups.
Tom.
> Try:
>
> InputStream in = getClass().getResourceAsStream("/data/myData.txt");
>
> That should work for any OSGi platform.
>
> Kind regards,
>
> Peter Kriens
>
> PN> Hello folks,
>
> PN> I need to read the content of a (text) file which is part of my plug-in.
> PN> I found a way to do this, but I feel I did it in a rather awkward
> PN> manner. Look at what I wrote:
>
> PN> =====snip=======
> PN> String path = "/data/myData.txt" ;
> PN> Bundle b = Platform.getBundle(PLUGIN_NAME);
> PN> URL url = Platform.find(b, new Path(path));
> PN> URL localUrl = null ;
> PN> InputStream is = null ;
> PN> InputStreamReader isr = null ;
> PN> try {
> PN> localUrl = Platform.resolve(url);
> PN> is = localUrl.openStream();
> PN> isr = new InputStreamReader(is);
> PN> } catch (IOException e) {
> PN> // TODO Auto-generated catch block
> PN> e.printStackTrace();
> PN> }
> PN> =====snap=======
>
> PN> The key seems to be to get an IFile for my URL, then the IFile will give
> PN> me the InputStream. But I could not figure out how to do this, hence the
> PN> hack (?) with Platform.resolve() and the localURL.
> PN> Or is this actually the way it must be done?
>
> PN> All hints appreciated.
>
>
> PN> Norbert
> PN> _______________________________________________
> PN> platform-core-dev mailing list
> PN> platform-core-dev@xxxxxxxxxxx
> PN> https://dev.eclipse.org/mailman/listinfo/platform-core-dev
>
>
> --
> Peter Kriens Mob +33633746480
> 9C, Avenue St. Drézéry Tel +33467542167
> 34160 Beaulieu, France Tel +15123514821
> AOL,Yahoo pkriens ICQ 255570717
>
> _______________________________________________
> platform-core-dev mailing list
> platform-core-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-core-dev