In java under Windows, how do I find a redirected Desktop folder?(在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()
这篇关于在Windows下的java中,如何找到重定向的Desktop文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在Windows下的java中,如何找到重定向的Desktop文件夹?


基础教程推荐
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01