package ftp2;
import java.io.*;
import java.net.*;
public class ClientFTP {
private Socket s=null;
private String ip="localhost";
private int port=8082;
public ClientFTP() {
creationConnection();
}
private void creationConnection() {
try {
s=new Socket(ip,port);
} catch (Exception e) {
// TODO: handle exception
}
}
private void getFile() {
String savePath="I:\\";
int bufferSize=8193;
byte[] buf=new byte[bufferSize];
int passedlen=0;
long length=0;
try {
DataInputStream dis=new DataInputStream(new BufferedInputStream(s.getInputStream()));
savePath+=dis.readUTF();
DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(savePath)));
length=dis.readLong();
System.out.println("文件长度:"+length+"\n");
while (true) {
int read=0;
if(dis!=null){
read=dis.read(buf);
}
passedlen+=read;
if (read==-1) {
break;
}
dos.write(buf,0,read);
}
System.out.println("接收文件另存为:"+savePath+"\n");
dos.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
new ClientFTP().getFile();
}
}
ClientFTP.rar_文件传输
版权申诉
44 浏览量
2022-09-24
01:37:09
上传
评论
收藏 684B RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/5f02f331e1ea4222a10b21da48ddddbe_weixin_42651748.jpg!1)
JonSco
- 粉丝: 77
- 资源: 1万+
最新资源
- Windows平台下的实用应用软件集
- 迅雷_8.01.0.9024.apk
- 基于Python基于pygame库开发的飞机大战射击游戏,在游戏中,玩家控制一架飞船,在太空中射击飞行的小行星以获得分数
- 基于python 实现多模态的动态用户属性挖掘系统
- 窗体动态视觉呈现效果或窗体动画化展示效果
- 本资源包涵盖了丰富的设计辅助功能,包括标注、文本编辑、路径操作、颜色管理、画板调整、包装设计、拼版、设计优化、输出设置和效果处理
- 城市鎏金风素材PPT.pptx
- 305建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\水1TJ-卫生间大样031020.dwg
- business鎏金风格.pptx
- 305建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\水1-C型平面031014.dwg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)