views:

135

answers:

1

I am developing web method for webservice in java. In this web method I have to read image from my images folder which resides in my webservice project folder. I am using the code as follows.

@WebMethod(operationName = "getAddvertisementImage")
public Vector getAddvertisementImage()
{
    Image image = null;
    Vector imageList = new Vector();

    try
    {
     File file = new File("E:/SBTS/SBTSWebservice/web/adv_btm.jpg");
     image = ImageIO.read(file);
     imageList.add(image);
    }
  catch (IOException e)
  {
        e.printStackTrace();
  }
    return imageList;
}

I am unable to read image from images folder.I am getting error image file "input file can't read" at image = ImageIO.read(file); how to resolve this issue ? Is there any mistake in my code or is there any other way to read image ? if there is any mistake in my code then can you proide me the code or link through which i can resolve the above issue.

+3  A: 

Is the E:\ drive mapped on your web server? The Java compiler has no idea that you might access files outside of its scope and how it could tell your web server to map a network drive or a local hard disk which is attached to your development computer.

The solution is to put the image file into the same directory as the Java source file and then use

InputStream in = getClass().getResourceAsStream("adv_btm.jpg");

Check that your IDE (or whatever you use to build your application) does copy the image file in the same directory where it creates the .class file. Then it should work.

Aaron Digulla