This discussion is archived
1 Reply Latest reply: Oct 20, 2012 3:23 PM by baftos RSS

Applet: how to write a file ?

Hurukan Newbie
Currently Being Moderated
This thread is the sequel of this one but concerns a different question: Applet: can not read file using getResource()

I'm happy, signing the Applet resolved the fact that I couldn't get the URL resource from the *.jar* file.
Now, this is my question:

If I want to write/create a file on the computer executing the Applet, the jvm launches an exception telling me the path is incorrect, not found.
The server runs on Linux and the clients are mostly Windows XP/Seven workstations.

1) do I have to take care about the file separators for cross-platform issues ? On Windows the file separator is different than Linux/Mac OS, of course.
2) how can I get the default local directory at client side ?
3) is that a good idea to map a "ramdisk" to avoid the security checks related to the access of the local file system by the Applet to write/create/modify some files ? The idea is to write to this ramdisk the files instead of writing them to the local file system using FileOutputStream() -- I only need 1Go at most.

My first idea was to write into the *.jar* file as I could take resource FROM the *.jar* I expected that it was possible to put resource TO the *.jar*, but I was wrong.
As the Applet is run by the client this feature may not be possible.

I really don't know, when an Applet is launched, if at the file system level there was a "root entry" for a potential file system access (saving temporary datas, and so on...) and if this entry existed where the jvm located it.

I needed to get the resource then modify it, save it in order to print it. Right now, I can get it, modify it but can't save it ^^

Thanx in advance for the future enlightments ^^

PS: it works if I do not specify a path in the file name, but I just wanted to know if it is possible to get the path of the local file system, to create particular files in it.

Edited by: Hurukan on Oct 20, 2012 1:52 PM
  • 1. Re: Applet: how to write a file ?
    baftos Expert
    Currently Being Moderated
    1) do I have to take care about the file separators for cross-platform issues ? On Windows the file separator is different than Linux/Mac OS, of course.
    I think / works on any platform, but it is safer to use File.separator.
    2) how can I get the default local directory at client side ?
    new File(".").getAbsolutePath()
    3) is that a good idea to map a "ramdisk" to avoid the security checks related to the access of the local file system by the Applet to write/create/modify some files ? The idea is to write to this ramdisk the files instead of writing them to the local file system using FileOutputStream() -- I only need 1Go at most.
    No. Your applet is already signed, so you should be able to use the file system, as far as the normal (Windows) user rights allow. You have some problems right now, but they are solvable.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points