Skip to main content

How to store capture image in url path?

1 reply [Last post]
Joined: 2012-06-25

I want to capture screenshot image should store in url like this

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) {
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 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.
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.