-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
29 lines (27 loc) · 954 Bytes
/
Copy pathServer.java
File metadata and controls
29 lines (27 loc) · 954 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
package Net2;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(5555);
System.out.println("等待客户端上传文件:");
Socket s = ss. accept();
InputStream is =s.getInputStream();
//创建字节输出流,向指定服务器中输入用户上传的文件
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("6.txt"));
byte [] by=new byte[1024*8];
BufferedInputStream bis =new BufferedInputStream(s.getInputStream());
int num = 0 ;
while((num=bis.read())!=-1){
bos.write(by,0,num);
}
bos.close();
bis.close();
s.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}