How to read a file fram an Applet in NS and IE

Posted on 1998-05-15
Medium Priority
Last Modified: 2012-05-05
Could anyone be so kind to explain, how I read a textfile in to an applet, in both NetScape Communicator, and Internet Explorer >4.0. I need a common way, so I can use the same applet. Please explain every security aspect involved.
Your solution should be able to read the file on either a local file system, or the net.

Need more information, just ask !!!

Sources is welcome :-)
Question by:KE

Expert Comment

ID: 1221065
I want to know what you mean by a local file system. Is it the filesystem of the client on which the browser is running or is it the filesystem of the host from which the applet is loaded.

Just remember one thing, An applet is not allowed to open, read/write files, open a socket connection to any host other than the host from which it is loaded.

if it is the filesystem of the host from which the applet is loaded, you need to write a proxy server (a java application which listens at a particular socket port and receives and processes requests - use ServerSocket) at the host which need to be running when the applet gets executed. The applet uses a socket connection to connect to that proxy server and forwards the request of reading the file to the proxy server  which reads the file and sends it back to the applet thru the socket connection.

Now if you want an applet to read the file from web, again the applet passes the url to the proxy server application which inturn uses the URL class to access that url, read its content and pass it onto the applet thru the socket connection.

See the java telnet applet in developer.javasoft.com site which employes a proxy server to emulate the telnet application.

So, if you want to read file from the file system from which the applet has originated or from the net, no special security considerations are required. Just use a proxy server. If you feel that this approach is too cumbersome, you need to sign the applet. Again here comes the problems with the incompatabilities of browsers and there is no  way to sign the applet that supports both ie and netscape browsers (because of browser wars).

If you want to read the data from the local file system of the client browser system, you need to sign the applet (the procedure varies for different browsers).

For more info go to
and see the java security chapter.

For more info on signing the applets for netscape and ie go thru these to articles which explain in step by step manner how to do that in both these browsers


Dont think that i am giving the pointers. The author of the articles is an expert and he can explain the things in a more clear way than me.


Author Comment

ID: 1221066
Thanks, for your huge answer.

I know it's a little late, however I was about to change the text of the question with some additional information.

I need to read (and only read) 5 ASCII based data files and some images, into a memory structure in the applet. In the meantime between your answer, I was looking at various methods to do this.
I found that I might be able to put the files into the distributed JAR file. The documentation states, that there should be no security restrictions to a JAR file - and if so, I would be very happy.
What I'm trying to figure now, is how to read a file from an JAR archive.
Currently I'm using this method to read a file:
BufferedReader in = new BufferedReader(new InputStreamReader(theURL.openStream()));
(which fails in Netscape)
How do I get this to work with JAR archives ?


Expert Comment

ID: 1221067

Whether it is a jar file or any other file, the basic rule is
"An applet cannot read or write files since the browser security manager doesnt allow it to do that".

You can go thru the applet security restrictions page if you want.
A jar file is a file like any other file and u will read it using jar api (very simple api). But still, note that since you want to read a file, you will have to open a file which the applet security manager doesnt allow !!.

I have the source code
for applet security manager (for applet viewer) and i saw that clearly the security manager is not allowing to do that.

There is no way that you can read the files from jar archive. If you found the answer, i would be glad to use that one. I went thru many books and finally i have to resort to understanding the source code for appletviewer security manager and i found that it is not allowed unless it is signed.

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 1221068
OK, I understand.

But if you can load an image from a JAR into your toolbars etc. (without any security restrictions) then I suppose you can load an ASCII file as well - Well, I don't know if you actually can do it, but it sounds resonable.

However I'm seeking the easiest way of getting external data into my applet. I don't actually mind if it's compiled into the code, but I don't know how to do this either.

So what do you think is the easiest way of reading (or compiling) images and ASCII files into the memory of the Applet ?


Author Comment

ID: 1221069
I've found that I can use getResourceAsStream(), and I guess the next part would be, to get the JAR signed for use in NetScape (IE runs perfect).


Expert Comment

ID: 1221070
Actualy, you can read any file you want as a stream if you read it from the server from both MSIE and Netscape. The problems start once it has been written on the local file system.

Additionaly, there is a free class lib available that can read data and immage files from a JAR or zip file, you interested?

Expert Comment

ID: 1221071
If you have access to the web server that is serving the applet, you could write a servlet to serve the files you need, and then the applet can get them through a socket connection to the servlet.

Author Comment

ID: 1221072
I'm looking for a solution, which will work on a local filesystem (i.e. CD-ROM). IE works perfectly, but NetScape throws a lot of exceptions, about verification etc.

OK, but as mentioned to jpk, I'm looking for a solution that will work on a local filesystem. As I understand, servlets is not supported unless you have a server ?


Accepted Solution

evijay earned 400 total points
ID: 1221073

To read file from local file system
go to this example


This uses javakey. Now, for netscape you have to use zigbert and for ie you have to use cabsign tools

The procedure is available in


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question