在Windows下的java中,如何找到重定向的Desktop文件夹?
我知道使用 .NET 语言,例如 C#,可以做类似的事情
I know using .NET languages such as C#, one can do something like
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
查找桌面的重定向位置.但是,在 Java 下,我想不出一个好的方法来做到这一点.在不使用 JNI 的情况下,从 Java 中查找重定向的用户桌面目录的最合适方法是什么?此处的特定目的是为了管理桌面快捷方式(如果用户需要的话),用于 Java Web Start 应用程序.
to find the redirected location of the Desktop. However, under Java, I cannot think of a good way to do this. What is the most appropriate way to find a redirected user Desktop directory from Java, without using JNI? The specific purpose here is for the purposes of managing a desktop shortcut, if the user wants one, for a Java Web Start application.
此应用程序需要写入应用程序数据"树以及可选地写入桌面.我假设 %APPDATA%
始终正确填充,即使文件夹被重定向,以查找应用程序数据"树.所以我的悬而未决的问题是如何可靠地找到桌面文件夹.
This application needs to write to the "Application Data" tree as well as optionally to the Desktop. I am making the assumption that %APPDATA%
is always correctly populated, even when folders are redirected, for finding the "Application Data" tree. So my open question is how to reliably find the Desktop folder.
注意:我相信 Java 系统属性 ${user.home}
实际上(和错误) 通过注册表项定位用户的桌面目录,然后尝试向上导航一个目录以找到主"目录.当没有目录被重定向时,这可以正常工作,否则可能会或可能不会返回有用的东西.
NOTE: I believe that the Java system property ${user.home}
actually (and erroneously) locates the user's Desktop directory via registry keys and then tries to navigate up one directory to find the "home" directory. This works fine when no directories are redirected, and otherwise may or may not return something useful.
推荐答案
FileSystemView filesys = FileSystemView.getFileSystemView();
filesys.getHomeDirectory()
相关文章