SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:One approach is to use DataOutputStream on the client. You first use writeUTF to write the file name, then writeLong to write the file size (also very important).
The server then uses DataInputStream. It first uses readUTF to read the file name, then readLong to read the file size. Let's say that value is x. You then read exactly x bytes, not all until the end of the line:
Note that the while loop's condition has changed quite a bit. First of all, there's the additional check to see if the remaining size is not 0. Second, the read is limited to the minimum of the buffer length and the remaining size. For most loop iterations this size is the buffer length (and therefore identical to read(buffer)), but the last block(s) will only read as many bytes as necessary; size will be smaller than buffer.length (and therefore can safely be cast to int).
Mads Nielsen wrote:I am unsure how to implement the DataOutputStream stream in the client code.?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Check the last piece of code in my previous post. I admit I made a mistake by not creating a new variable myself in my first post.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Check the last piece of code in my previous post. I admit I made a mistake by not creating a new variable myself in my first post.
Mauricio Corrêa wrote:I hope I have contributed...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Don't get me started about those stupid light bulbs. |