Obed Miranda
Obed Miranda

Reputation: 51

How to create automatic path on a java application

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?

Upvotes: 5

Views: 143

Answers (1)

Jesper
Jesper

Reputation: 206816

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

String FILENAME = System.getProperty("user.home") + "\\Desktop\\" + x + ".png";

Upvotes: 5

Related Questions