开发者

Cache Path from Java

开发者_如何学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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜