|
Re: resource loading [message #314231 is a reply to message #314211] |
Thu, 05 April 2007 12:11 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Alex,
Most often you'd use a path that doesn't start with "/" to look up the
resource in the same folder as the .class file itself.
Aleksandr Krvavets wrote:
> Hello,
>
> I have a file in my plugin that I am trying to read. I am using
> getClass().getResource() to load the file but always get
> NullPointerException. What's the input string to getResource() should
> be to correctly identify the file? I am trying to pass the whole
> package path to the file, but nothing works.
>
> thanks,
> Alex
>
|
|
|
Re: resource loading [message #314245 is a reply to message #314231] |
Thu, 05 April 2007 14:32 |
Aleksandr Kravets Messages: 30 Registered: July 2009 |
Member |
|
|
Thanks Ed,
Right, the file that is in the same package as executing class I can
get, but I meant file in the plugin's root directory:
com.ak.myplugin:
src
xslt
file.xslt
I want to read file.xslt from class in src directory.
Also, when I create file from with the executing class' directory:
URL url = this.getClass().getResource("file.xslt");
File file = new File(url.toString());
I get file with path:
bundleresource:\1187\com\ak\wizard\file.xslt
Then, when I try to read this file using BufferedReader, the file cannot
be found.
thanks,
Alex
Ed Merks wrote:
> Alex,
>
> Most often you'd use a path that doesn't start with "/" to look up the
> resource in the same folder as the .class file itself.
>
>
> Aleksandr Krvavets wrote:
>> Hello,
>>
>> I have a file in my plugin that I am trying to read. I am using
>> getClass().getResource() to load the file but always get
>> NullPointerException. What's the input string to getResource() should
>> be to correctly identify the file? I am trying to pass the whole
>> package path to the file, but nothing works.
>>
>> thanks,
>> Alex
>>
|
|
|
Re: resource loading [message #314254 is a reply to message #314245] |
Thu, 05 April 2007 15:42 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Alex,
I think you'd use this.getClass().getResource("/file.xslt") but you
can't assume that the URL that comes back is a file: URL. It could be a
jar, or as you see, an OSGi-specific scheme. Can't you use
URL.openStream directly? You could also use a URL of the form
platform:/plugin/<plugin-ID>/file.xslt directly and open the stream for
that.
Aleksandr Krvavets wrote:
> Thanks Ed,
>
> Right, the file that is in the same package as executing class I can
> get, but I meant file in the plugin's root directory:
>
> com.ak.myplugin:
> src
> xslt
> file.xslt
>
> I want to read file.xslt from class in src directory.
>
> Also, when I create file from with the executing class' directory:
>
> URL url = this.getClass().getResource("file.xslt");
> File file = new File(url.toString());
>
> I get file with path:
>
> bundleresource:\1187\com\ak\wizard\file.xslt
>
> Then, when I try to read this file using BufferedReader, the file
> cannot be found.
>
> thanks,
> Alex
>
> Ed Merks wrote:
>> Alex,
>>
>> Most often you'd use a path that doesn't start with "/" to look up
>> the resource in the same folder as the .class file itself.
>>
>>
>> Aleksandr Krvavets wrote:
>>> Hello,
>>>
>>> I have a file in my plugin that I am trying to read. I am using
>>> getClass().getResource() to load the file but always get
>>> NullPointerException. What's the input string to getResource()
>>> should be to correctly identify the file? I am trying to pass the
>>> whole package path to the file, but nothing works.
>>>
>>> thanks,
>>> Alex
>>>
|
|
|
Powered by
FUDForum. Page generated in 0.02906 seconds