This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes FileOutputStream and JPG file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FileOutputStream and JPG file." Watch "FileOutputStream and JPG file." New topic
Author

FileOutputStream and JPG file.

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I use Applet to send a file to Servlet. Now my coding is only working for Text and small GIF icon. The saved file, if it is in JPG and large GIF file, will be corrupted.

How to fix it ?

Thanks.

applet : send a file


Servlet : receive a file
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41051
    
  43
Binary data (like an image file) is not character data - you can't convert it to a string. Just do a "out.write(buffer1, 0, bytesRead)" instead.


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
We like to reserve this forum for "easy" questions, so I feel I shall have to move this thread.
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Ulf Dittmer wrote:Binary data (like an image file) is not character data - you can't convert it to a string. Just do a "out.write(buffer1, 0, bytesRead)" instead.

Thanks. it works.
 
Consider Paul's rocket mass heater.
 
subject: FileOutputStream and JPG file.
 
Similar Threads
Transferring file name then file data over socket
Using Apache Commons Codec
Sending a file over socket
copying files over a network
Socket connection program works for localhost but not for other ip