在跨平台Java中将文件存储在用户目录中 [英] Storing a file in the user's directory in cross-platform Java
问题描述
我有一个可以在Mac和Windows上运行的Java应用程序,无需安装即可直接从CD/DVD中获得.现在,我需要在本地文件系统上的某个位置存储一个包含每个用户数据(例如收藏夹等)的文件,以便可以将其写入.
I have a Java application that runs on Mac and Windows, directly off a CD/DVD with no installation. Now, I need to store a file containing per-user data (think favourites etc.) somewhere on the local file system, so that it can be written to.
那么,您认为该文件在哪里呢?我在想类似的东西:
So, where do you think is a good location for this file? I am thinking something like:
<USER_DOCUMENTS_AND_SETTINGS>/application data/myapp/favourites.db
<USER_HOME_DIR>/.myapp/favourites.db
for mac/nix
<USER_DOCUMENTS_AND_SETTINGS>/application data/myapp/favourites.db
for windows
<USER_HOME_DIR>/.myapp/favourites.db
for mac/nix
有什么想法吗? 有人知道在Java中确定这些路径的最佳方法吗?
Thoughts? And does anyone know the best way to determine these paths within Java?
推荐答案
System.getProperty("user.home")
这篇关于在跨平台Java中将文件存储在用户目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!