Hi,
I have a servlet that sometimes sends static pages to the client.
It works fine for text files(text/plain, text/xml, etc), however when I try
to use it for a gif, it doesn't work.

Following is the relevant code i'm using. There may be syntax errors as i
haven't run the code.. I just need to know a method of reading a gif properly.

When I open up a program that listens to socket connections, i can see the
http resp, which looks normal. When I open it in gimp, i get the message
"bogus character 0x00. Ignoring"

Thanks in advance,
Rob

res.setContentType("image/gif");

PrintWriter toClient = res.getWriter();
toClient.println(readfile("/path.to/image.gif"));
toClient.close();

public String readfile(String infilepath) {
  InputStream inf = new FileInputStream(infilepath);
  BufferedInputStream bin = new BufferedInputStream(inf);
  int len = bin.available();
  byte[] buf = new byte[len];
  bin.read(buf,0,len);
  return new String(buf);
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to