This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 41133
    
  45
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: 38044
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileOutputStream and JPG file.
 
Similar Threads
Using Apache Commons Codec
Sending a file over socket
Transferring file name then file data over socket
copying files over a network
Socket connection program works for localhost but not for other ip