Skip to main content

How to store capture image in url path?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
indira55
Offline
Joined: 2012-06-25

Hi,
I want to capture screenshot image should store in url like this
http://localhost/jobqueen/website/screenshots/

this my program
public class Image{
..............................

public static void writeImage(BufferedImage img, String fileLocation,
String extension) {
try {
BufferedImage bi = img;
File outputfile = new File(fileLocation);
ImageIO.write(bi, extension, outputfile);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String createTimeStampStr() throws Exception {
...................
}
public void randomImage(String uname) throws Exception {
.....................

Robot robot = new Robot();
BufferedImage bi = robot.createScreenCapture(new Rectangle(1000,900));

String file = "http://localhost/website/screenshots/" + username + createTimeStampStr() + ".PNG";
writeImage( bi, file, "PNG");
}
}

when I run this program i am getting this error

java.io.FileNotFoundException: http:\localhost\website\screenshots\amit1220120625_110414.PNG (The filename,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jxqlovejava
Offline
Joined: 2012-05-23

You could try replacing the url path with your disk path, such as "C:\\captureimgs1.png".
Or you may try this(I'm not sure that it will work, but you could give it a try):
File outputfile = new File(new URI(fileLocation));

In a B/S or C/S application, if client upload a file such as an image, then it should be stored in server. Normally, it's implemented by passing the bytes of the image to back end, then back end read it and write it back to local disk.
For example, I upload an image "1.png", and my name is "jxqlovejava", then server may store my image as "C:\\userimgs\\jxqlovejava_1.png".

Directly using new File("http:\localhost\website\screenshots\amit1220120625_110414.PNG") may not be allowed, because the path corresponds server's disk path, and you have no write privilege. And only server end itself can decide whether to write it or not.