Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Images and Text Files  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how a JApplet can access images on the server it is in using a ClassLoader, but when it comes to accessing a simple text file, it can't easily be done.

Is there any easy way to read a simple text file on a server without using signed applets or policy files?

Thanks for any help, its much appreciated
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leaping Lizards!

I've actually solved it...

When I run the applet on browser, the contents of the file stored on the server are displayed on the JLabel

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that I can read a text file, I wonder if its possible for a JApplet to read the contents of a zip file stored on the server.

Currently I have this code to read contents of zip file...

But this doesn't work on server, is there any way to kind of combine the code in message above with this code, so an applet can read the names of files stored in a zip that is on the server?

Thanks
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty much the same idea: you already know how to get an InputStream that reads a file from the server. Now wrap that InputStream in a ZipInputStream and read ZipEntry objects from that.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ARCHIVE attribute of the APPLET tag allows one to specify a comma-separated list of files. You could package your applet in a JAR, specify both that file and the zip file in the ARCHIVE attribute and load the text file using getResourceAsStream(), as the text file would be accessible through the class loader at that point.
Failing that, you could try to use java.net.URL to download the file and extract the text file on the client.
[ May 09, 2007: Message edited by: Joe Ess ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent stuff!

I haven't tried the ARCHIVE thing yet, but this code below...

Displays all the folders and files (on separate lines) of the contents of the zip file.

Is this the right idea?
Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a much cooler approach than the HTTP stuff I suggested the other day. Does this work because the applet classpath includes the jar that holds the file and the browser downloads the jar to satisfy the classpath?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure, but I'm a bit dissapointed now...
When I load the page ZIP test it has to 137 files/directories, but it takes much too long.

So annoying, I fixed one aspect by making the applet code flexible so any zip of images can be used, but now it takes too long to load, so its not very user friendly.

I guess its because it has to get the data over a network, and 137 items might take 30 seconds or so...

Is there any way this can be made faster, I'll take a look at the archive thing too.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!