Cache Path from Java
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?
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.
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.
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.
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.
精彩评论