Board index » jbuilder » Get the current path.

Get the current path.


2004-12-16 12:25:12 AM
jbuilder17
Hi group,
I need to know the current path of my running class. How can I do it?
Thanks in advance,
Nuno Paquete
 
 

Re:Get the current path.

Nuno Paquete wrote:
Quote
Hi group,

I need to know the current path of my running class. How can I do it?

Thanks in advance,

Nuno Paquete
Why? What do you need it for?
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Get the current path.

Nuno Paquete wrote:
Quote
I need to know the current path of my running class. How can I do it?
You can use the getResource method of the Class class to get it.
Something like the code below, which may have minor errors since I
haven't compiled it. The basic idea is to take the class name (ex.
com.foo.Bar) and convert it to a resource name that points to the class
file (com/foo/Bar.class).
String name= object.getClass().getName().replace('.', '/') + ".class";
URL path = object.getClass().getResource(name);
Having said that, Lori's question of "Why?" is a good one. In the most
general case, you can't even be sure that there is a path that
corresponds to the class. The class might not have been loaded from a
file or a URL. It may have been created dynamically, loaded from a byte
stream, etc. You just don't know.
--
Gillmer J. Derge [TeamB]
 

{smallsort}

Re:Get the current path.

Lori M Olson [TeamB] wrote:
Quote
Nuno Paquete wrote:

>Hi group,
>
>I need to know the current path of my running class. How can I do it?
>
>Thanks in advance,
>
>Nuno Paquete

Why? What do you need it for?

Hi.
Sorry if I haven't made myself clear.
I'm developing an application that needs to load a file from the HD and that
file is placed in the same directory of the running class.
I'm using Swi-Prolog library, and to load the file mentioned above I need to
type this code:
Term arg[] = {new Atom("c:\\path_to_file\\file.pl")};
But instead of passing the entire path I want to pass the relative path,
like we do with HTML.
Thanks for your post,
Nuno Paquete
 

Re:Get the current path.

Nuno Paquete wrote:
Quote

Hi.
Sorry if I haven't made myself clear.
I'm developing an application that needs to load a file from the HD and that
file is placed in the same directory of the running class.
I'm using Swi-Prolog library, and to load the file mentioned above I need to
type this code:
Term arg[] = {new Atom("c:\\path_to_file\\file.pl")};
But instead of passing the entire path I want to pass the relative path,
like we do with HTML.

Thanks for your post,

Nuno Paquete
Ok. Well, Gillmer's solution should work, as long as the file is placed
in the same directory as one of your classes.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html