如何使用Java获取独立于OS的系统用户文档,图片,音乐文件夹? [英] How can I get system user documents, pictures, music folders independent of OS using Java?
问题描述
当我正在处理我的项目时,我收到了一个要求:我需要获取系统用户文档文件夹(例如Windows的我的文档和Linux和Mac OS X的文档)。我需要为所有操作系统获取它。我怎样才能做到这一点?
While I was working on my project I received a requirement: I need to get the system user documents folder (like "My Documents" for Windows and "Documents" for Linux and Mac OS X). I need to get it for all the operating systems. How can I do this?
我可以使用 System.getProperty(user.home)
获取用户根目录。我需要使用Java来满足此要求的解决方案。
I can get the user root directory by using System.getProperty("user.home")
. I need a solution for this requirement using Java.
推荐答案
默认系统Documents或Pictures文件夹的位置是高度依赖操作系统,依赖于分发,依赖于用户设置。我能想到的最接近的事情是开始查看用户主目录,您可以从 System.getProperty(user.home)
获取。
The location of the default system "Documents" or "Pictures" folder is highly operating-system dependent, distribution dependent, user setting dependent. The closest thing I can come up with is to start looking in the user home directory which you can get from System.getProperty("user.home")
.
然后你可以实现一些启发式基于
You could then implement some heuristics based on
-
System.getProperty (os.name)
操作系统名称 -
System.getProperty(os.arch)
操作系统架构(应该不那么有趣) -
System.getProperty(os.version)
操作系统版本
System.getProperty("os.name")
Operating system nameSystem.getProperty("os.arch")
Operating system architecture (should be less interesting)System.getProperty("os.version")
Operating system version
这篇关于如何使用Java获取独立于OS的系统用户文档,图片,音乐文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!