InputStream is = new FileInputStream("/apphome/pictures/image.jpg"); OutputStream os = response.getOutputStream(); byte[] buffer = new byte[256*1024]; //256k while (true) { int n = is.read(buffer); if (n < 0) break; os.write(buffer, 0, n); } is.close(); os.close();
--- On Fri, 9/26/08, Dave <[EMAIL PROTECTED]> wrote: From: Dave <[EMAIL PROTECTED]> Subject: image download To: "Tomcat Users List" <users@tomcat.apache.org> Date: Friday, September 26, 2008, 6:33 PM For <img src="http://domain.com/servlet/pictures/image.jpg"/> in servlet get method, InputStream is = new FileInputStream("/apphome/pictures/image.jpg"); OutputStream os = response.getOutputStream(); byte[] buffer = new byte[256*1024]; //256k while (true) { int n = is.read(buffer); if (n < 0) return; os.write(buffer, 0, n); } is.close(); os.close(); Is this the right way? Sometimes only the half image is shown on web page. Is there a more efficient and robust way? How about for audio/video files? I want to take at how Tomcat does it. Could anyone tell me which class? thanks Dave