0

Just as a first step in a Java project I'm trying to get a image loaded into BufferedImage, I only succeed in getting the error message "cant read input file". I tried placing the image in asource folder within the project and giving the path of the image on my computer but I cant seen to get it to work.

package imageProcessing;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class image
{

  public image()
  {
    try
    {
      // the line that reads the image file
      BufferedImage image = ImageIO.read(new File("me.jpg"));

      // work with the image here ...
    } 
    catch (IOException e)
    {
      // log the exception
      // re-throw if desired
    }
  }

  public static void main(String[] args)
  {
    new image();
  }

}
Ciaran
  • 23
  • 6
  • How do you compile and run your program? In what directories are you placing the various files? – Wim Deblauwe May 10 '21 at 14:56
  • I'm using eclipse, I created a source folder , which I can navigate to on the C drive ....eclipse/projectname/ – Ciaran May 10 '21 at 15:02
  • There is no `me.jpg` in the current working folder, or the file is not readable. If you are uncertain exactly what the current working folder is, try `System.out.println(new File("").getAbsolutePath())`. If you want to read images as part of your project, don't use a file, use a resource (`getClass().getResource(..)`) and make sure you have the resource in your class path. – Harald K May 10 '21 at 15:04
  • Thanks , I'll try and use getClass(). getResource(..). Slightly burned out with it just at the moment. Thanks again. – Ciaran May 10 '21 at 15:32

0 Answers0