有一个默认值(FileSystem?)Java中的位置。
例如,当您实例化一个JFileChooser而没有指定要在其中打开哪个文件夹时,它将在该默认位置打开。
我需要将这个默认位置作为一个Path对象(不使用JFileChooser,只是为了解释)。
我怎么才能得到它呢?
发布于 2013-07-19 08:49:15
您应该能够从用户的主目录System.getProperty("user.home")创建一个Path
就像..。
Path path = FileSystems.getDefault().getPath(System.getProperty("user.home"));已更新
JFileChooser使用FileSystemView来获取它的“默认”目录
Path path = FileSystemView.getFileSystemView().getDefaultDirectory().toPath()同样,您也可以使用类似于...
Path docs = FileSystems.getDefault().getPath(System.getProperty("user.home"), "Documents");
Path myDocs = FileSystems.getDefault().getPath(System.getProperty("user.home"), "My Documents");
Path userHome = FileSystems.getDefault().getPath(System.getProperty("user.home"));并测试每一个,看看它们是否真的存在
发布于 2013-07-19 08:19:04
不确定这是否是你要找的东西...对于JFileChooser,默认目录通常是“我的文档”文件夹,而在Unix上则是用户的主目录。Source。
如果您想要工作目录的路径,那么CurrentClass.class.getProtectionDomain().getCodeSource().getLocation().getPath().
https://stackoverflow.com/questions/17736129
复制相似问题