在Java应用程序中保存文件的好地方是什么? [英] What's a good place to save a file to in a Java app?
问题描述
我有一个需要保存单个文本文件的Web Start应用程序。我想知道我应该在哪里编写文件,这样它就可以在一个整洁的地方运行,无论它运行的是什么平台。
如果我得到这样的文件路径...
新文件(System.getProperty(user.dir)+ System.getProperty(file.separator) )+test.txt);
...然后文件写在某处好看且不显眼Linux,但在Windows上的桌面上,以及我正在运行该程序的图标,这并不理想,因为用户不一定需要知道或关心该文件是否存在。
是否有一种良好的,独立于平台的获取文件路径的方式,允许我将文件保存在某处谨慎?我不太关心它最终的位置,只要它不在桌面上的完整视图中。
谢谢。
Neil
user.dir
是当前的工作目录;使用 user.home
i nstead和 java.io.tmpdir
用于临时文件。
这是 Java 1.5的预定义属性列表。/ p> I have a Web Start application which needs to save a single text file. I would like to know where I should write the file, such that it goes in a tidy place regardless of the platform it runs on. If I get my filepath like this... ... then the file gets written somewhere nice and inconspicuous on Linux, but on the desktop on Windows, alongside the icon I'm running the program from, and that's not ideal because the user shouldn't necessarily need to know or care that the file exists. Is there a good, platform-independent way of getting a file path that allows me to save a file somewhere discreet? I don't much care where it ends up, providing it's not in full view on the desktop. Thanks. Neil Here's the list of predefined properties for Java 1.5. 这篇关于在Java应用程序中保存文件的好地方是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!new File(System.getProperty("user.dir") + System.getProperty("file.separator") + "test.txt);
user.dir
is the current working directory; use user.home
instead and java.io.tmpdir
for temporary files.