Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In java under Windows, how do I find a redirected Desktop folder?

I know using .NET languages such as C#, one can do something like

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)

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.

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.

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.

like image 744
Eddie Avatar asked Feb 20 '09 17:02

Eddie


People also ask

How do I redirect a folder in Windows?

Right-click a folder that you want to redirect (for example, Documents), and then select Properties. In the Properties dialog box, from the Setting box, select Basic - Redirect everyone's folder to the same location.

What is folder redirection used for?

Folder Redirection enables users and administrators to redirect the path of a known folder to a new location, manually or by using Group Policy. The new location can be a folder on the local computer or a directory on a file share.

Is Folder Redirection a good idea?

Folder Redirection allows saving data regardless of storage location and separates user data from profile data decreasing the time required to log on. Other advantages include: Data is stored on a server where it can be backed up.


1 Answers

FileSystemView filesys = FileSystemView.getFileSystemView();

filesys.getHomeDirectory()
like image 180
Russ Bradberry Avatar answered Oct 04 '22 18:10

Russ Bradberry