获取Java中的默认的根目录 [英] Getting the default root directory in Java
本文介绍了获取Java中的默认的根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做一个基本的文件浏览器,并想知道如何得到默认的根目录。我知道, java.io.File.listRoots()
给出了所有的根(对于我来说, A:\\,C:\\,D:\\ E:\\,F:\\,G:\\,H:\\,I:\\,L:\\ T:\\,U:\\,X:\\ Y:\\,Z:\\
),但我希望用户主要使用一(那就是,在其上的操作系统),所以我从哪里开始浏览知道了。
I'm making a basic file browser, and want to know how to get the default root directory. I know that java.io.File.listRoots()
gives all the roots (for me it's A:\, C:\, D:\, E:\, F:\, G:\, H:\, I:\, L:\ T:\, U:\, X:\, Y:\, Z:\
), but I want the one the user uses primarily (i.e. the one with the Operating system on it) so I know from where to start the browsing.
推荐答案
不知道这是任何帮助,但你可以尝试:
Not sure if this is of any help, but you could try:
import javax.swing.filechooser.*;
FileSystemView.getFileSystemView().getRoots()[0];
或
FileSystemView.getFileSystemView().getHomeDirectory();
或
System.getProperty("user.dir");
在过去的片段,您可以通过向上导航使用的getParent(),直到空
返回得到的根目录。
这篇关于获取Java中的默认的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文