Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Desktop path in java

Tags:

java

desktop

I think this will work only on an English language Windows installation:

System.getProperty("user.home") + "/Desktop"; 

How can I make this work for non English Windows?

like image 491
jumar Avatar asked Jul 03 '09 19:07

jumar


People also ask

How do I find my Desktop path?

In the navigation pane on the left side, right-click Desktop and select Properties. In the Properties window, click the Location tab. The directory path to the desktop is displayed in the text field on the Location tab.

How do I find the path of a file in Java?

In Java, for NIO Path, we can use path. toAbsolutePath() to get the file path; For legacy IO File, we can use file. getAbsolutePath() to get the file path.

What is path in Java?

A Path can represent a root, a root and a sequence of names, or simply one or more name elements. A Path is considered to be an empty path if it consists solely of one name element that is empty. Accessing a file using an empty path is equivalent to accessing the default directory of the file system.


2 Answers

I use a french version of Windows and with it the instruction:

System.getProperty("user.home") + "/Desktop"; 

works fine for me.

like image 57
Amlaa Avatar answered Sep 30 '22 11:09

Amlaa


I think this is the same question... but I'm not sure!:

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

Reading it I would expect that solution to return the user.home, but apparently not, and the link in the answer comments back that up. Haven't tried it myself.

I guess by using JFileChooser the solution will require a non-headless JVM, but you are probably running one of them.

like image 36
Dan Gravell Avatar answered Sep 30 '22 10:09

Dan Gravell