Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets Writing to File

 
Sean McGurk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Like many of the visitors to on this forum, I refuse to believe that applets are not able to write to files that are located within the same local folder, which leads my to believe that I have a syntax problem with my code.
I am using :

to define the URL. However, I get the following error message when I go to run the code:
MalformedURLException: no protocol: words.txt
I am unable to state either:

or

possibly because the program is not an applet, but rather contains methods that are called by an applet (a servlet?)
Does anyone know how to or have any examples of an applet writing to a local file ?
Thanks and regards,
Sean
 
Tim Holloway
Saloon Keeper
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't like secure environments, just switch to C#!
Have you considered what "same local folder" means? The folder from which the user's web browser was loaded (e.g. C:\Windows)? The user's desktop folder? Or did you expect to "cd" into C:\Windows\System" and write file "MFC42D.DLL" as a "same local folder file"?
A URL is not a file. It DEMANDS a protocol. Not "words.txt", but "http://words.txt" Or if you prefer, "file:///words.txt". Using a URL object instead of a File object won't help you though - Java knows what you're ultimately trying to do.
Sorry to disappoint you. Sun designed security into Java from day 1. They must have done a fairly good job - I've seen more Microsoft security alerts this year than I can count, but none from Sun. It's an inconvenience, but then so is getting your system nuked by a rogue applet. If you want to write to a local file, you have to do things that make it obvious to the user that foul deeds are possible - sign your applet or make it run as a standalone application.
 
Robert Stewart
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely this isn't that complicated. I think what Sean was saying was if the html page that contains the applet exists at www.host.com/index.html and there is a file at www.host.com/data.txt, there must be an easy way to write some text to the file? I have been looking into this for two days now. I'm not interested in using servlets, JDBC, JSP, or whatever. I don't want to write or read anything on the local machine. I just want to save a couple pieces of data on my own server. Is that wrong?
sincerely,
Frustrated Developer
any help VERY appreciated
 
Tim Holloway
Saloon Keeper
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you think that the applet should be able to unrestrictedly write files to the SERVER!!!?? That's where www.host.com is - not on the client's local machine.
Yeah, you can do that - it's called "Code Red"!
Seriously, to write a file to the server, the server has to be willing to accept the file. You can do this fairly simply by opening a URL connection on the client side and aiming it at a servlet on the server that figures out what actual directory to put it in, what actual name to give it, and any other post-prcoessing of the data it wants to do, then does the writing.
A WEB server is <i>not</i> a file server! Considering what's been going on lately, it's just as well. I've had over 1500 attempts by Code Red to break into my webservers since August 1, including a good many from "Code Red II", which WOULD like to write files on my server = without permission!.
 
Sean McGurk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup- can now read from and write to a file located within the same directory. I'm just running the applet on a stand-alone machine. I know that if I need to read from or write to files across a network, that the applet needs to be signed, but if anyone is looking for an application that can do a simple read/ write to and from a local file, then I can assure you it IS possible!!!
Sean
 
jim, valenta
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean,
Any indication how you accomplished this? Just the direction that you took,
jim
 
niliep
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
You do successfully read/write file to your harddisc?? How to do that? I have try as many time as I could. But still cannot work.
What is signing Applet? Do I need to sign it to read/write file??
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic