如何在OS X中使用Java查找用户的“文档"文件夹? [英] How do I find the user's 'Documents' folder with Java in OS X?

查看:100
本文介绍了如何在OS X中使用Java查找用户的“文档"文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户的文档"文件夹中创建一个目录,但是到目前为止,我只发现了如何获取用户的主目录:

I'd like to create a directory in the user's 'Documents' folder, but so far I've only found out how to get the user's home directory:

javax.swing.JFileChooser fr = new javax.swing.JFileChooser();
javax.swing.filechooser.FileSystemView fw = fr.getFileSystemView();
this.userDirectory = fw.getDefaultDirectory();

在Windows中,以上代码返回我的文档"目录,这很好,该目录应该放在新文档中.在OS X上,它仅返回主目录.

In Windows the above code returns the 'My Documents' directory, which is great, that's where the new documents are supposed to go. On OS X it only returns the home directory.

在返回的路径中添加文档"会导致本地化问题.

Adding 'Documents' to the returned path would cause problems with localization.

我该怎么做?

推荐答案

System.getProperty("user.home")+ File.separator +"Documents";

System.getProperty("user.home")+File.separator+"Documents";

不要担心本地化,请看:

And don't worry about with localization, look:

macb:Documents laullon$ pwd
/Users/laullon/Documents

我的OS X是西班牙语的.

My OS X is in Spanish.

这篇关于如何在OS X中使用Java查找用户的“文档"文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆