(Java) Copy files trough sockets -
this question has answer here:
today i'm having troubles files in java.
the issue is: i'm trying copy file (not text, kind) 1 side of socket another. read file bufferedreader (byte byte) , write them on file fileoutputstream.
it works fine, when open file is not same te original, writting bytes on text file or that.
a piece of code:
        in = new bufferedinputstream(s.getinputstream());         byte b[] = new byte[max_length];         file f = new file(name);         fileoutputstream fos = new fileoutputstream(name);         for(int = 0; < segments; i++){             in.read(b,i*max_length,max_length);             fos.write(b);         } where s oppened socket (working fine), name name of file , segments number of segments sent trough socket (segments of max_length).
thanks help.
you assume can read max_length bytes each read call. may not case.
read returns number of bytes read stream. write many bytes output stream in each loop iteration.
Comments
Post a Comment