Reputation: 63
I currently have the following code:
ImageIO.write(imageBlue, "PNG", new File("c://imageBlue.PNG"));
But I want the program to write it to my Desktop, no matter when Directory I am currently in.
Upvotes: 2
Views: 136
Reputation: 4207
Only this configuration needed,
ImageIO.write(imageBlue, "PNG", new File(System.getProperty("user.home") + "/Desktop");
Upvotes: 3
Reputation: 201399
You can use System.getProperty(String)
to get the user.home
System Property. Then, use that to get the Desktop
. Finally, use that to get your desired output File
. Something like,
String homeFldr = System.getProperty("user.home");
File desktop = new File(homeFldr, "Desktop");
ImageIO.write(imageBlue, "PNG", new File(desktop, "imageBlue.PNG"));
Upvotes: 6
Reputation: 1565
You should change the path of to following :
C:\Users\{your-user-id}\Desktop
Upvotes: 1