This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Where is this code located - in a JSP page? I'm guessing it is, since you are posting to the JSP forum. A JSP page really can't (and shouldn't) use the output stream. If the response consists of an image you need move this code to a servlet.
JSP compilers will often add characters to the output stream going to the browser. Since the primary intent for JSP is textual output (Mainly HTML or XML) these characters aren't a problem. If you're trying to write binary data to a browser, however, they will become a problem. This is why it's best to do this with a servlet.
Thanks folks ,I used a servlet and it worked well. The code i earlier tried was straight from the myfaces example i downloaded from Myfaces. its contained in the file_upload.java file and it used a JSP to emit images which is wrong like you two gentlemen pointed out and this i agree with