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?
You can get the user's home directory from the system property user.home
:
String FILENAME = System.getProperty("user.home") + "\\Desktop\\" + x + ".png";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With