Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Problem reading image from input Stream

807605Jun 21 2007 — edited Jun 21 2007
I'm having a problem reading an image through an input stream. It gives me the error
Premature end of JPEG file
sun.awt.image.ImageFormatException: JPEG datastream contains no image
and my code looks like
public Image getImage(String name, String command){
		if(command.equals(pCode)){
			Image image=null;
			System.out.println(name);
			InputStream is = getClass().getResourceAsStream(name);
			BufferedInputStream bis = new BufferedInputStream(is);
			 byte[] byBuf =new byte[10000]; 
			  
			  try {
				int byteRead = bis.read(byBuf,0,10000);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			  image = Toolkit.getDefaultToolkit().createImage(byBuf);
			return image;
		}
		return null;
		
	}
And the string name looks when printed is: usr/images/PRLogo.jpg
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2007
Added on Jun 21 2007
1 comment
244 views