-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileSender.java
More file actions
58 lines (55 loc) · 1.35 KB
/
FileSender.java
File metadata and controls
58 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Filename: FileSender.java
*
* Author: Oxnz
* Email: yunxinyi@gmail.com
* Created: 2016-09-02 18:05:45 CST
* Last-update: 2016-09-02 18:05:45 CST
* Description: anchor
*
* Version: 0.0.1
* Revision: [NONE]
* Revision history: [NONE]
* Date Author Remarks: [NONE]
*
* License:
* Copyright (c) 2016 Oxnz
*
* Distributed under terms of the [LICENSE] license.
* [license]
*
*/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;
public class FileSender {
private static int PORT = 8000;
private static String ADDR = "192.168.249.247";
private static String FILE = "/path/to/file";
private static int BUFSIZ = 1<<20;
public static void main(String[] args) {
try {
File file = new File(FILE);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
Socket socket = new Socket(ADDR, PORT);
System.out.println("connected");
OutputStream os = socket.getOutputStream();
byte[] buffer = new byte[BUFSIZ];
for (int sz = 0; sz != -1; sz = bis.read(buffer)) {
os.write(buffer, 0, sz);
System.out.print(".");
}
os.flush();
bis.close();
fis.close();
os.close();
socket.close();
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
}
}