最新下载
热门教程
- 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();
}
}
}
相关文章
- 银与绯吉尔兰技能怎么样 吉尔兰战斗特性解析 07-14
- 异环异象管理局局长是谁 艾尔菲德角色详细介绍 07-14
- 欧意易ok官网下载版 欧意易app下载 07-14
- 迷你世界马车怎么做 马车制作方法介绍 07-14
- 碳碳岛许愿池有什么作用 许愿池建造方法介绍 07-14
- 最终幻想14水晶世界怎么招募雇员 招募雇员方法介绍 07-14