How to locate files? [message #459515] |
Mon, 04 December 2006 07:35  |
Eclipse User |
|
|
|
Originally posted by: florianwendland.freenet.de
Hello all,
I spend some hours by checking out, how to locate files on my system for my
rcp app.
I've have RCP Project 'Test' and subdir 'icons'. My filesystem looks like
this:
Path.../Test/icons/icon.gif
Now, I want to get icon.gif with Java-I/O-File like this:
File file = new File(hello.gif);
The problem is, that Eclipse didn't get the Path of the Prject, but of
eclipse intall directory:
c:\programme\eclipse\hello.gif
What is the common way, to locate a file in my project path? And how to
locate files if I am exproting my rcp app as a product?
May be this is a newbie questions, but I've tried so much possible results
and no one of these results had worked...
Thanks a lot
florian
------------------------------------------------------------ ----------------
----
Ich verwende die kostenlose Version von SPAMfighter,
die bei mir bis jetzt 3655 Spammails entfernt hat.
F
|
|
|
Re: How to locate files? [message #459516 is a reply to message #459515] |
Mon, 04 December 2006 07:40   |
Eclipse User |
|
|
|
Hi,
opening files part of your rcp-projects is really simple. You simply call
InputStream i =
Platform.getBundle("com.my.project").getResource("/icons/icon.gif ").openStream()
Tom
Florian Wendland schrieb:
> Hello all,
>
> I spend some hours by checking out, how to locate files on my system for my
> rcp app.
>
> I've have RCP Project 'Test' and subdir 'icons'. My filesystem looks like
> this:
>
> Path.../Test/icons/icon.gif
>
> Now, I want to get icon.gif with Java-I/O-File like this:
>
> File file = new File(hello.gif);
>
> The problem is, that Eclipse didn't get the Path of the Prject, but of
> eclipse intall directory:
>
> c:\programme\eclipse\hello.gif
>
>
> What is the common way, to locate a file in my project path? And how to
> locate files if I am exproting my rcp app as a product?
>
> May be this is a newbie questions, but I've tried so much possible results
> and no one of these results had worked...
>
> Thanks a lot
> florian
>
>
>
> ------------------------------------------------------------ ----------------
> ----
> Ich verwende die kostenlose Version von SPAMfighter,
> die bei mir bis jetzt 3655 Spammails entfernt hat.
> Für private Anwender ist SPAMfighter völlig kostenlos!
> Jetzt gratis testen: hier klicken.
>
>
|
|
|
Re: How to locate files? [message #459518 is a reply to message #459516] |
Mon, 04 December 2006 09:49   |
Eclipse User |
|
|
|
Hi Tom and Florian,
You might also consider using FileLocator, as follows:
Bundle bundle = ClassLoaderTestsActivator.getDefault().getBundle();
Path path = new Path ("ErpPersistence.jar");
URL url = FileLocator.find (bundle, path, null);
InputStream inputStream = url.openStream();
Charlie
Tom Schindl wrote:
> Hi,
>
> opening files part of your rcp-projects is really simple. You simply call
>
> InputStream i =
> Platform.getBundle("com.my.project").getResource("/icons/icon.gif ").openStream()
>
>
> Tom
>
> Florian Wendland schrieb:
>
>>Hello all,
>>
>>I spend some hours by checking out, how to locate files on my system for my
>>rcp app.
>>
>>I've have RCP Project 'Test' and subdir 'icons'. My filesystem looks like
>>this:
>>
>> Path.../Test/icons/icon.gif
>>
>>Now, I want to get icon.gif with Java-I/O-File like this:
>>
>> File file = new File(hello.gif);
>>
>>The problem is, that Eclipse didn't get the Path of the Prject, but of
>>eclipse intall directory:
>>
>> c:\programme\eclipse\hello.gif
>>
>>
>>What is the common way, to locate a file in my project path? And how to
>>locate files if I am exproting my rcp app as a product?
>>
>>May be this is a newbie questions, but I've tried so much possible results
>>and no one of these results had worked...
>>
>>Thanks a lot
>>florian
>>
>>
>>
>> ------------------------------------------------------------ ----------------
>>----
>>Ich verwende die kostenlose Version von SPAMfighter,
>>die bei mir bis jetzt 3655 Spammails entfernt hat.
>>Für private Anwender ist SPAMfighter völlig kostenlos!
>>Jetzt gratis testen: hier klicken.
>>
>>
>
>
|
|
|
|
Re: How to locate files? [message #459981 is a reply to message #459968] |
Sun, 10 December 2006 09:47  |
Eclipse User |
|
|
|
Florian Wendland wrote:
> Okay, that way works fine.
>
> But now, I have another problem concerning files. I have to readout a
> list of all files, which are stored in a special directory.
>
> Platform.getBundle(Activator.PLUGIN_ID).getResource(someEntr y))
>
> gets the URL of a single Resource. But how to get all the files in the
> directory of this resource?
>
> I've tried several ways, but I didn't find a solution for that.
normally your bundle is a jar file ... the URL that is returned from
getResource(*) would allow you to get an InputStream to that resource
without having to worry about where it is.
Remember, you should consider plugins and their directories and files
read-only when developing your plugin.
What are you trying to do? If you build a small number of files into a
directory and don't want to programmatically keep the list, you can use
Bundle#getEntry(*) to get the directory and then
FileLocator#toFileURL(url) to get it as a file:// url. This has the
advantage that if your plugin is delivered as a JAR, it will expand the
directory and contents for you (with the associated performance hits).
If you need a configuration directory then you probably need a different
approach.
Later,
PW
|
|
|
Powered by
FUDForum. Page generated in 0.48584 seconds