Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Client;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.net.Socket;
- public class fileReciever {
- public static void main(String[] args) {
- try {
- Socket sock = new Socket("127.0.0.1", 10001);
- DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
- DataInputStream dis = new DataInputStream(sock.getInputStream());
- String fileName = "cake.mp3";
- dos.writeUTF(fileName);
- FileOutputStream fos = new FileOutputStream("D:\\save\\" + fileName);
- int readCount = 0;
- byte[] buffer = new byte[8192];
- long start = System.currentTimeMillis();
- while((readCount = dis.read(buffer)) != -1) {
- fos.write(buffer, 0, readCount);
- }
- long end = System.currentTimeMillis();
- System.out.println("[8192] Saved Safely! : " + (end - start) + "ms");
- /*while(true) {
- int data = dis.read();
- if(data == -1) break;
- fos.write(data);
- }*/
- dos.close();
- dis.close();
- fos.close();
- sock.close();
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement