FileSystemView fsv = FileSystemView.getFileSystemView();
File com=fsv.getHomeDirectory();
//桌面真实路径
String Desktop = com.getPath();
System.out.println(Desktop);
windows 桌面真实路径 系统盘C盘情况下 C:\Users\Public\Desktop
FileSystemView为系统文件视图接口
分别有几个针对不同系统的实现类
实现类 | 对应系统 |
---|---|
WindowsFileSystemView | windows |
UnixFileSystemView | unix |
GenericFileSystemView | ubuntu |
可以使用FileSystemView接口获取一些系统文件目录的File对象进行File操作
API接口可以查看官方API文档
或者点击链接:
https://docs.oracle.com/javase/8/docs/api/javax/swing/filechooser/FileSystemView.html