我想在用户的'Documents'文件夹中创建一个目录,但到目前为止我只发现了如何获取用户的主目录:
javax.swing.JFileChooser fr = new javax.swing.JFileChooser();
javax.swing.filechooser.FileSystemView fw = fr.getFileSystemView();
this.userDirectory = fw.getDefaultDirectory();
Run Code Online (Sandbox Code Playgroud)
在Windows中,上面的代码返回"我的文档"目录,这是很好的,这是新文档应该去的地方.在OS X上,它只返回主目录.
将"文档"添加到返回的路径会导致本地化问题.
我怎样才能做到这一点?
小智 9
您想使用Apple的eio.FileManager扩展:
static public String documentsDirectory()
throws java.io.FileNotFoundException {
// From CarbonCore/Folders.h
final String kDocumentsDirectory = "docs";
return com.apple.eio.FileManager.findFolder(
com.apple.eio.FileManager.kUserDomain,
com.apple.eio.FileManager.OSTypeToInt(kDocumentsDirectory)
);
}
Run Code Online (Sandbox Code Playgroud)
小智 8
System.getProperty( "的user.home")+文件分割符+ "文档";
不要担心本地化,看看:
macb:Documents laullon$ pwd
/Users/laullon/Documents
Run Code Online (Sandbox Code Playgroud)
我的OS X是西班牙语.
| 归档时间: |
|
| 查看次数: |
11571 次 |
| 最近记录: |