Problem with FileWriter

A

ADH

Hi:

I'm writing a simple Web application that gets image data from a
third-party applet and writes it to a specified directory on a Web
server (this is done using a JSP and a JavaBean handling the file
upload.)

When I upload any *.jpg and attempt to write it to the server,
however, the size of the copied image on the server directory is
exactly the same, but when I try to open the file, I get "No Preview
Available" from Windows Picture and Fax Viewer, "Can't determine type"
from Microsoft Photo Editor, etc.

Here is the code that I used to read from the applet source and write
to the server:


try {
// get the image input from applet
ServletInputStream in = request.getInputStream();
FileOutputStream ostrm = new FileOutputStream("picture4.jpg");

byte[] readArray = new byte[1];
while((in.read(readArray)) != -1)
{
ostrm.write(readArray);
}
// close all streams
in.close();
ostrm.close();

return true;
} catch (Exception e) {
System.out.println("check console");
return false;
}

}

Can anyone help me out?
 
C

Chris

ADH said:
Hi:

I'm writing a simple Web application that gets image data from a
third-party applet and writes it to a specified directory on a Web
server (this is done using a JSP and a JavaBean handling the file
upload.)

When I upload any *.jpg and attempt to write it to the server,
however, the size of the copied image on the server directory is
exactly the same, but when I try to open the file, I get "No Preview
Available" from Windows Picture and Fax Viewer, "Can't determine type"
from Microsoft Photo Editor, etc.

Here is the code that I used to read from the applet source and write
to the server:

The code looks fine to me. Debug the problem by comparing the original file
to the file produced by your copy routine. Many text editors and most
operating systems have utilities that let you do file comparisons.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top