Opening files/directories on the server using an applet

Hi all,

I'm creating an Applet wich I want to list some files in a directory.

But when I create a new instance of File the getAbsolutePath() method returns something like:

C:\Documents and Settings\Gerard\Bureaublad\http:\80.56.221.202\applet

getPath() returns the good path. I want to open a directory on server. File.exists() returns false offcourse.

Here is a code example:

folder ="/applet";

File file =new File(getCodeBase().toString() + folder);

System.out.println(file.getAbsoluteFile());

What do I do wrong?

[638 byte] By [GeeBeea] at [2007-11-26 16:19:37]
# 1

The applet runs on the client, not on the server. Its filesystem is the client's filesystem, not the server's - and unless it's signed, it won't have access to that anyway.

If you want to access files on the server then the server will need to make them available, typically via HTTP.

In general, forget using filesystems in applets.

itchyscratchya at 2007-7-8 22:43:04 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for your reaction.My applet is signed, but I don't quite know how to list all files of a directory on the server. Could you give me a little example/URL of how to do this?Thanks againMessage was edited by: GeeBee
GeeBeea at 2007-7-8 22:43:04 > top of Java-index,Desktop,Core GUI APIs...
# 3
The applet runs on the client, not on the server. Its filesystem is the client's filesystem, not the server's. If you want to access the server filesystem try JSPs/Servlets, which run on the server.
itchyscratchya at 2007-7-8 22:43:04 > top of Java-index,Desktop,Core GUI APIs...
# 4

hi

itchyscratchy is absolutely right

here is what you have to do is simple applet servlet communication

1. Create an applet send the parameters like file name etcs which which u wana use.

2. Create a servlet that reads the file from the server and stream it back to the applet.

3. Call the servlet from the applet and read the stream in the applet and do what ever you want to do.

hope this helps

Surendra_Varmaa at 2007-7-8 22:43:04 > top of Java-index,Desktop,Core GUI APIs...
# 5
Thanks for your help! I wil try it (never used servlets before)Maybe I can connect to a php file wich returns it for me too.
GeeBeea at 2007-7-8 22:43:04 > top of Java-index,Desktop,Core GUI APIs...