View Single Post
  #1 (permalink)  
Old 08-04-2007, 05:11 PM
Nite Nite is offline
Member
 
Join Date: Aug 2007
Posts: 2
Nite is on a distinguished road
Problems sending file throught TCP sockets
I would like to transfer a file throught a tcp socket, here there is what the sender program does :

Code:
try{ File localFile = new File("shared/"+fileName); DataOutputStream oos = new DataOutputStream(socket.getOutputStream()); DataInputStream fis = new DataInputStream(new FileInputStream(localFile)); while(fis.available() > 0){ oos.writeByte(fis.readByte()); } } catch(Exception e){} }
and here what the receiver program does:

Code:
try{ File downloadFile = new File("incoming/"+fileName); downloadFile.createNewFile(); ois = new DataInputStream(connectionSocket.getInputStream()); fos = new DataOutputStream(new FileOutputStream(downloadFile)); while(ois.available() > 0){ fos.writeByte(ois.readByte()); } } catch(Exception e){} }

Where i m wrong? it doesnt work , it just create the new file in the incoming folder, but its size remains 0 byte

help a newbye please

Last edited by levent : 08-04-2007 at 06:44 PM. Reason: Code placed inside [code] tag.
Reply With Quote
Sponsored Links