java socket fileoutputstream can't close file -


i've write code transferring file on sockets, file transfers isn't closed after calling .close() method.

however file closes after closing "sockets", want keep connection open.

here server sends file client

server code

public  void sendfile(string sfilename) throws ioexception{     try{         in = new fileinputstream(sfilename);         out = socket.getoutputstream();         transferdata(in,out);     }     {         in.close();         in = null;         system.gc();     } } private void transferdata(inputstream in, outputstream out) throws ioexception  {     byte[] buf = new byte[8192];     int len = 0;     while(in.available()==0);     while ((len = in.read(buf)) != -1) {     out.write(buf, 0, len);     }     out.flush(); } 

client code :

public  void recievefile(string rfilename) throws ioexception{     try{         in = socket.getinputstream();         system.out.println("reciever file : " + rfilename);         out = new fileoutputstream(rfilename);         transferdata(in,out);     }     finally{         out.flush();         out.close();         out = null;         system.gc();     } } private void transferdata(inputstream in, outputstream out) throws ioexception  {     byte[] buf = new byte[8192];     int len = 0;     while(in.available()==0);     while ((len = in.read(buf)) != -1) {     out.write(buf, 0, len);     }     out.flush(); } 

what wrong code ?

i think should use socket.shutdownoutput()


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -