• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Servlets

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some code that writes Images to a screen, but the images come up looking really bad. There must be a mistake in my code, see anything?

private void GIF(String f, HttpServletResponse res)

{
try
{
res.setContentType("image/gif");
OutputStream out = res.getOutputStream();
System.out.println("################" + res.getOutputStream());

BufferedReader br = new BufferedReader(new FileReader(f));

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

char[] cbuf = new char[1024]; // read/write 1024 bytes at a time..
int len;

while ((len = br.read(cbuf, 0, 1023)) > 0)
{
bw.write(cbuf,0,len);
}
bw.flush();
bw.close();
}

catch(Exception e)

{
System.out.println("Problem rendering image" + e);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!