Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create automatic path on a java application

Tags:

java

I'm creating a little application to take a picture of my screen. I can save it automatically on my desktop using this path:

String FILENAME = "C:\\Users\\obed\\Desktop\\" + x + ".png";
 ImageIO.write(image, "png", new File(FILENAME));

where Obed is my username. How can I change "obed" automatically to the user´s pc name, so in that way I can run my application on any computer?

like image 680
Obed Miranda Avatar asked Oct 27 '14 19:10

Obed Miranda


1 Answers

You can get the user's home directory from the system property user.home:

String FILENAME = System.getProperty("user.home") + "\\Desktop\\" + x + ".png";
like image 78
Jesper Avatar answered Nov 01 '22 08:11

Jesper