tags:

views:

39

answers:

4

Is there any method that returns some path that is accessible from any Java applet application, from any user, any operating system (Windows, Linux, etc) for saving cache?

+2  A: 
System.getProperty("java.io.tmpdir");

You also might want to take a look at a blog post titled java.io.tmpdir Inconsitency since the above-mentioned method adds a trailing slash on Windows and Solaris but doesn't do so on Linux and OSX.

Saul
A: 

If you just need a temporary file you can use

File temp = File.createTempFile("filename", ".suffix");

This file will be created in a OS-dependent location. It will be deleted automatically when your application exits.

Peter Knego
A: 

Besides using the tempdir, note that applets launched in a plugin2 architecture JRE (1.6.0_10+) can hook into the JWS API, and thereby use the PersistenceService. Here is a small demo of the PersistenceService.

Edit: Note the PersistenceService can be used X-Plat and from a sand-box.

Andrew Thompson
A: 

If you're writing an applet (which runs in the web browser), the security manager will prevent you from writing to files unless you the applet is signed.

Ken Bloom