Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. String dirPath = ...;
  2.  
  3. ServerSocket serverSocket = ...;
  4. Socket socket = serverSocket.accept();
  5.  
  6. BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
  7. DataInputStream dis = new DataInputStream(bis);
  8.  
  9. int filesCount = dis.readInt();
  10. File[] files = new File[filesCount];
  11.  
  12. for(int i = 0; i < filesCount; i++)
  13. {
  14. long fileLength = dis.readLong();
  15. String fileName = dis.readUTF();
  16.  
  17. files[i] = new File(dirPath + "/" + fileName);
  18.  
  19. FileOutputStream fos = new FileOutputStream(files[i]);
  20. BufferedOutputStream bos = new BufferedOutputStream(fos);
  21.  
  22. for(int j = 0; j < fileLength; j++) bos.write(bis.read());
  23.  
  24. bos.close();
  25. }
  26.  
  27. dis.close();
Add Comment
Please, Sign In to add comment