Skip to main content

how to resolve filenotfound exception?

1 reply [Last post]
indira55
Offline
Joined: 2012-06-25
Points: 0

Hi,

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, directory name, or volume label syntax is incorrect)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.(RandomAccessFile.java:212)
at javax.imageio.stream.FileImageOutputStream.(FileImageOutputStream.java:53)
at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:393)
at javax.imageio.ImageIO.write(ImageIO.java:1514)
at Image.writeImage(Image.java:29)
at Image.randomImage(Image.java:71)
at Image.run(Image.java:120)
at java.lang.Thread.run(Thread.java:619)
java.lang.NullPointerException
at javax.imageio.ImageIO.write(ImageIO.java:1523)
at Image.writeImage(Image.java:29)
at Image.randomImage(Image.java:71)
at Image.run(Image.java:120)
at java.lang.Thread.run(Thread.java:619)

plz need help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
grelf
Offline
Joined: 2007-11-14
Points: 0

The error message is telling you the answer: your file path contains invalid characters. Colons in the time stamp perhaps? Spaces in the user name?