0

So yeah, I am making a Text-Based RPG, in the form of an applet. This applet writes to your APPDATA directory when opened. It works in the IDE, but when I try it in Firefox, it comes up with an error message. HERE is the link.

File otherWorldDirectory = new File(System.getenv("APPDATA") + "\\.otherWorld");

if (!otherWorldDirectory.exists()) {
    //Adding the folder .otherWorld to the APPDATA
    otherWorldDirectory.mkdir();
    System.out.println("Directory '.otherWorld' created.");
} else {
    //The folder .otherWorld already exists.
    System.out.println("Directory '.otherWorld' is not created, it exists.");
}
Exikle
  • 1,155
  • 2
  • 18
  • 42
Jay
  • 143
  • 2
  • 11
  • You can't simply write to a local folder on the client machine - this is a security flaw. Revisit your design! See [this](http://stackoverflow.com/questions/3504671/alternative-to-java-applet-for-file-system-access-from-web). – home Aug 24 '11 at 17:24
  • Then how? Do I need to sign the .jar file? Or just save it to a different folder? – Jay Aug 24 '11 at 17:26

2 Answers2

2

This is the point of applets. They cannot access user's disk unless they are "trusted". You have to sign your applet to be able to access user's disk.

AlexR
  • 114,158
  • 16
  • 130
  • 208
1

This applet writes to your APPDATA directory when opened.

Don't do that. Mac. & *nix machines will not have it, & applets have access to a number of forms of persistence that is x-plat.

  • Sand-boxed
    1. Cookies
    2. The JNLP API PersistenceService as seen in this demo..
  • Trusted
    1. user.home as an x-plat location to store information.
    2. Preferences
    3. All the ways open to sand-boxed apps.
    4. ...
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433