how to save on the desktop?

0

My question is how to make a file path String that always points to the desktop regardless of whether the application is changed from one PC to another. I mean that if the application changes it from pc always keep a file on the desktop.

Thanks

    
asked by Marco Salazar 11.10.2018 в 14:40
source

2 answers

2

It has several forms, in my first codes when I needed to do something similar, I did it with

String desktopPath = System.getProperty("user.home") + "/Desktop";
System.out.println(desktopPath.replace("\", "/"));

is simple, and returns the String of the path of the user's home, independent if it is Linux or Windows.
The bad thing is if the Desktop folder does not exist inside the user's home.

Another way is to do it with FileSystemView (if not it bothers you to combine Java Core with Java Swing)

File home = FileSystemView.getFileSystemView().getHomeDirectory(); 

and thus you get a File with the information

and if you need it as String String absPath = home.getAbsolutePath();

Searching for StackOverflow in English I found an answer only for windows maybe you're interested in

    
answered by 11.10.2018 в 19:43
0

The Desktop folder is not in USERS. In Windows 10 it is inside USERS and within the username. I do not know if that can help you. Maybe if you put% USERS /% / DESKTOP% it works. You will tell me. Greetings

    
answered by 11.10.2018 в 15:36