最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
javs Socket传压缩文件,并文件打开接收到的文件
时间:2022-06-29 00:44:01 编辑:袖梨 来源:一聚教程网
public class TranFileServer {
public static void main(String[] args){
ServerSocket server;
Socket st;
try {
server = new ServerSocket(4000);
st = server.accept();
File receivedfile = new File( "src/2.rar ");
BufferedInputStream bin = new BufferedInputStream(st.getInputStream());
FileOutputStream fout = new FileOutputStream(receivedfile);
int i = bin.read();
while(i != -1){
fout.write(i);
i = bin.read();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
客户端:
public class TranFileClient {
public static void main(String[] args){
try {
Socket st = new Socket( "localhost ",4000);
File f = new File( "2.rar ");
FileInputStream fin = new FileInputStream(f);
BufferedOutputStream bout = new BufferedOutputStream(st.getOutputStream());
int size = fin.available();
for(int i = 0;i < size; i++){
bout.write(fin.read());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
相关文章
- 《弓箭传说2》新手玩法介绍 01-16
- 《地下城与勇士:起源》断桥烟雨多买多送活动内容一览 01-16
- 《差不多高手》醉拳龙技能特点分享 01-16
- 《鬼谷八荒》毕方尾羽解除限制道具推荐 01-16
- 《地下城与勇士:起源》阿拉德首次迎新春活动内容一览 01-16
- 《差不多高手》情圣技能特点分享 01-16