-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
32 lines (28 loc) · 946 Bytes
/
Copy pathClient.java
File metadata and controls
32 lines (28 loc) · 946 Bytes
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
package Net2;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.net.Socket;
public class Client {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost",5555);
//读取本地文件
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d://ioutf.txt"));
//创建缓冲区
byte[] by =new byte[1024*8];
int n =0;
// 读取本地文件
while((n= bis.read())!=-1){
//将读取的数据写入指定服务器
bos.write(by,0,n);
}
bos.close();
bis.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}