• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing to a file

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am new to applets. I would like to know if I can have an applet which resides on my machine write to a file in the same folder on my machine. Do I have to change some security policy or something in my browser to allow this to be done?
Basically what I wish to achieve is to be able to write to a file on the local pc using a standalone web page containing an applet and this applet class will reside on my local pc. No server is involved.
Thanks
Poonam
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poonam,
Unfortunately, I don't know any simple answer to your question. I believe that the precise method of dealing with security issues (such as writing to file) can vary from browser to browser. Also, there may be a need to create a signed applet.
The link below seems to explain this a little better:
http://developer.java.sun.com/developer/onlineTraining/Security/Fundamentals/contents.html
You might want to start with the section on Browser-level Security.
Many people ask about how to get more privileges (like writing to file) for their applets. I haven't done this, so I will have to look into it. If anyone has experience/advice in this area, we would love to hear from you!
However, Poonam, I am a little confused by your last statement:

Basically what I wish to achieve is to be able to write to a file on the local pc using a standalone web page containing an applet and this applet class will reside on my local pc. No server is involved.

If you are only working on the local machine, with no need to communicate across a network, why bother with applet security? Why not just write an application, which would not be hindered by the same restrictions as applets?
Please let us know.
Stephanie
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephanie. The reason I would like to write an applet is that I need to carry out some tests using javascript from a browser and log the results to a file. So a Java application will not do. But i would be runnning these on my local pc so I was wondering if the applet can write to a file in the same folder as where it originated from without going through any security policy issues.
Poonam
Originally posted by Stephanie Grasson:
Poonam,
Unfortunately, I don't know any simple answer to your question. I believe that the precise method of dealing with security issues (such as writing to file) can vary from browser to browser. Also, there may be a need to create a signed applet.
The link below seems to explain this a little better:
http://developer.java.sun.com/developer/onlineTraining/Security/Fundamentals/content s.html
You might want to start with the section on Browser-level Security.
Many people ask about how to get more privileges (like writing to file) for their applets. I haven't done this, so I will have to look into it. If anyone has experience/advice in this area, we would love to hear from you!
However, Poonam, I am a little confused by your last statement:
If you are only working on the local machine, with no need to communicate across a network, why bother with applet security? Why not just write an application, which would not be hindered by the same restrictions as applets?
Please let us know.
Stephanie

 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poonam,
Thanks for the update. You said that:

The reason I would like to write an applet is that I need to carry out some tests using javascript from a browser and log the results to a file. So a Java application will not do. But i would be runnning these on my local pc so I was wondering if the applet can write to a file in the same folder as where it originated from without going through any security policy issues.

This sounds like you are just doing testing and have no intention of releasing the applet for use by others, you're just using it on your machine. With that in mind, I have the following suggestion:
Please note: I AM NOT CLAIMING THE FOLLOWING SAMPLE CODE IS SAFE FOR RELEASE. I DO NOT RECOMMEND RELEASING IT. IT IS ONLY FOR YOUR BENEFIT IN TESTING ON YOUR LOCAL MACHINE.
With that in mind, I have tested it on a WinNT4.0 machine with Netscape 4.73. (I chose Netscape because you can download it for free and it runs on multiple platforms). The code does succeed in writing a file to the same folder where the applet originated. Be sure when you compile to include the java40.jar file in your classpath. If you have a recent version of Netscape on your machine, you will have this file. Just do a search for it.

here is the html:

I figured this out using the information in the original link I gave you, as well as this site:
http://developer.netscape.com/index.html?cp=dev01thom
When you run the applet, you will get a dialog asking for permission to write to the local file system. If you click the "Grant" button, the file will be written. (I didn't check the other options, but since this is what you are trying to do, I don't know why you would click "Deny".
Anyway, I hope this helps you. Please remember, it's just a quick and dirty program for testing. Please let us know how it goes.
Stephanie
 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code works fine with Netscape, but IE 5.0 only shows a grey box. Is there any way to run it with the EI ??
Thx Brain
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netscape and IE implement security in different ways. For more information on IE, see this site:
http://developer.java.sun.com/developer/onlineTraining/Security/Fundamentals/Security.html#secIE
Hope it helps.
Stephanie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic