• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Applet + file access

 
Ranch Hand
Posts: 128
MS IE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I found out that, in the IE java console, the following lines of code in my applet was'nt able to create a directory in the first place.
(1)File directory= new File(/D:/Sylvester/IndexSearch);
(2)System.out.println("Directory filename:"+directory.getName());
(3)File[] filesInDir=directory.listFiles();
(4)for(File f: filesInDir){
(5)System.out.println(f.getName());}

(1) does not run in InternetExplorer v6.0. The java console shows an exception as follows:
access denied (java.io.FilePermission D:\Sylvester\IndexSearch read)

IndexSearch is the name of the directory where my files reside. My program displays the appropriate file based on the file name.

the above process was run in Internet Explorer v6.0
The program worked in Applet viewer. I wrote a few debugging statements as shown above ((2) and (5)) and everything worked well in applet viewer, although it does'nt allow showDocument(), which I used later in the program to work.

I hope the problem has been clearly specified. Do you think that Internet Explorer is causing me problems? This same program worked in IE a few days ago when I was initially running the program. I did not change any permissions for files. They are all readable.
[ April 20, 2006: Message edited by: Allen Sylvester ]
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, applets can not access the local file system as a security precaution (for details and workarounds, see this wiki page). The appletviewer is a bit less restrictive, so it may allow things that a browser would not allow.

When it worked a few days ago, maybe you ran the applet locally off your hard disk, and now you're running it from the server? That would make a difference, permission-wise.

showDocument needs a browser environment, so it's not surprising that the call wouldn't succeed.
[ April 20, 2006: Message edited by: Ulf Dittmer ]
 
Allen Bandela
Ranch Hand
Posts: 128
MS IE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dittmer,
Actually, even now I am running the applet from the local file system. I don't know why it worked it earlier.
I've read that the applet can make network connections back to the host from where it came from. All my files that I want my applet to access are on the host where it resides. Is it still restricted from accessing those files? My applet does not have to access the user's hard disk.

I am trying to use digital signatures with the help of jarsigner tool. I hope that will help.
Thanks for your help.

By the way, I set the argument for File() above in line (1) dynamically.
i.e I use getDocumentBase().getPath() to get the path for
File directory=new File(path*)
and not the local D directory . I just showed the path above for explanatory purpose.

[ April 20, 2006: Message edited by: Allen Sylvester ]
[ April 20, 2006: Message edited by: Allen Sylvester ]
 
Bartender
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Allen Sylvester:

I've read that the applet can make network connections back to the host from where it came from. All my files that I want my applet to access are on the host where it resides. Is it still restricted from accessing those files? My applet does not have to access the user's hard disk.



You can't access the files by creating a File instance. You have to download the files through a network connection (either a bare Socket or URL/URLConnection/HttpURLConnection) which means they must be accessable to a server process on the host.
 
Allen Bandela
Ranch Hand
Posts: 128
MS IE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand now that I cannot access the files on the host machine without creating a TCP connection with a URL class etc.

Could anyone tell me if its possible to use any of java's classes from an applet to get the names of all the files on the host machine( the machine where the html file that contains the applet is present).

A URL can refer to a directory. If so, can I use an input stream reader to read every file in that directory? I want to know the file names, so I can calculate dynamically which of those files I can display. How should I do this.
 
Joe Ess
Bartender
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you request a directory or "index.html" and there is no existing file called "index.html", a web server will usually return an HTML document with a directory listing. Most web servers have this feature turned off as an unscrupulous user can obtain access to files you may wish to remain hidden. You can either enable this feature or write a servlet (or whatever server-side dynamic web application your server supports) to return directory listings for partiticular web contexts.
 
Allen Bandela
Ranch Hand
Posts: 128
MS IE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , but I'm using only an applet for my program. The management prevents from using any web server. So, I have to constrain myself only to an applet. Is there any way I can get a list of files in the home directory where my applet exists without using a web server?
[ April 24, 2006: Message edited by: Allen Sylvester ]
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is no web server involved, then wouldn't you be much easier off if instead of an applet you used a regular desktop application?

Getting a list of files is done by new File(directoryName).list() or .listFiles()
 
Allen Bandela
Ranch Hand
Posts: 128
MS IE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Because I have to use it on the net from a webpage. I think its just impossible.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!