Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Returning current directory.

0 views
Skip to first unread message

DaveS

unread,
Sep 25, 2002, 6:01:46 PM9/25/02
to
Hi.
Could anyone tell me how to return the directory than an application is
running from?

I tried Applet.getCodeBase() but this just caused the program to crash when
the code was run. It gave the following error:

java.lang.NullPointerException at java.applet.Applet.getCodeBase(Unknown
Source)

Any help would be appreciated.

Thanks.


Fahd Shariff

unread,
Sep 26, 2002, 3:45:45 AM9/26/02
to
Hi,

Instead of getCodeBase() you could try getDocumentBase(). I have not
tried this myself but i'm sure its worth a try:

Returns an absolute URL naming the directory of the document in which
the applet is embedded. For example, suppose an applet is contained
within the document:

http://www.fahdshariff.cjb.net/projects/applet.html

The document base is:

http://www.fahdshariff.cjb.net/projects/

I'm curious to know if it works!

Fahd
www.fahdshariff.cjb.net

"DaveS" <daj...@york.ac.uk> wrote in message news:<amtbpa$3at$1...@pump1.york.ac.uk>...

David Patterson

unread,
Sep 26, 2002, 5:38:25 AM9/26/02
to
"DaveS" <daj...@york.ac.uk> wrote in message news:<amtbpa$3at$1...@pump1.york.ac.uk>...

How about:

File myDir = new File( "." );
String fullPath = myDir.getCanonicalPath();
/* getCanonicalPath() may throw an IOException, so you have to catch or
reflect it */

David Patterson
patt...@comcast.net

0 new messages