Java客户端给服务器发送文件
来源:互联网 发布:华大基因与阿里云 编辑:程序博客网 时间:2024/05/06 14:50
public static void sendMsg(String url,int port) throws Exception{
int size=0,length=0;
Socket s = null;
OutputStream os = null;
InputStream is = null;
FileInputStream fis = null;
try {
s = new Socket("localhost",port);
os =s.getOutputStream();
is = s.getInputStream();
File sendFile = new File(url);
fis = new FileInputStream(sendFile);
byte[] buffer = new byte[1024*5];
int i=0;
while((size=is.read(buffer))!=-1){
System.out.println(size+" ");
os.write(buffer,0,size);
os.flush();
System.out.println("第"+ ++i+"次输出");
}
} catch (IOException e) {
e.printStackTrace();
}finally{
is.close();
fis.close();
os.close();
s.close();
int size=0,length=0;
Socket s = null;
OutputStream os = null;
InputStream is = null;
FileInputStream fis = null;
try {
s = new Socket("localhost",port);
os =s.getOutputStream();
is = s.getInputStream();
File sendFile = new File(url);
fis = new FileInputStream(sendFile);
byte[] buffer = new byte[1024*5];
int i=0;
while((size=is.read(buffer))!=-1){
System.out.println(size+" ");
os.write(buffer,0,size);
os.flush();
System.out.println("第"+ ++i+"次输出");
}
} catch (IOException e) {
e.printStackTrace();
}finally{
is.close();
fis.close();
os.close();
s.close();
}
期中
String url = "//home//test//my//cache//1.odc";
port::对应端口
0 0
- Java客户端给服务器发送文件
- Java学习日记8:文件上传工具类的实现和服务器给客户端发送图片
- java实现客户端向服务器发送文件的操作
- 客户端将手机号发送给服务器,服务器将包含该手机号文件名发送给客户端
- Java给服务端发送文件
- 使用ngx_lua发送文件给服务器
- WEB客户端发送给WEB服务器的HTTP请求消息
- windows 服务器 服务端程序发送RST给客户端
- Redis服务器如何发送回复内容给客户端
- 服务器+客户端软件+java邮件发送jar
- java客户端向服务器发送数据
- Java客户端通过Http发送POST请求上传文件到web服务器
- [Java Web]服务器获取远程文件并Zip打包给客户端下载
- Test_Java_网络编程(客户端向服务器发送字符串,服务器将字符串反转后发送给客户端)
- linux下实现服务器与客户端(连接时给客户端发送时间)
- TCP编程例三:从客户端发送文件给服务器端,服务器端保存到本地,并返回“发送成功”给客户端。
- 如何将存在服务器上的word文件在客户端浏览的时候以html页的形式发送给用户?
- 服务端接收到客户端发送的文件名,并把文件的内容返回给客户端
- 算法导论 顺序双向栈——两个栈共享同一存储空间
- iOS开发之 网页视图和时间选择器
- confirm中的“取消"问题
- django 1.8 官方文档翻译:5-1-4 内建的Widget
- [Android开发] 错误No resource found that matches the given name 'Theme.AppCompat.Light'.
- Java客户端给服务器发送文件
- win7,win8,win10下配置 Java 环境变量(系统变量)
- Android性能优化总结
- Android漂亮的UI库集合
- NSAssert调试程序
- iOS--常用的宏
- 页面Loading js插件
- 让apache支持https的设置步骤
- PHP 保持中文编码 json_encode 函数