package com.company.s3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket; public class Server {
public static void main(String[] args) throws Exception{
byte[] byteArray=new byte[2048];
ServerSocket serverSocket=new ServerSocket(8088);
Socket socket=serverSocket.accept(); InputStream inputStream=socket.getInputStream();
int readLength=inputStream.read(byteArray); FileOutputStream pngoutputstream=new FileOutputStream(new File("e:\\2.jpg"));
while (readLength!=-1){
pngoutputstream.write(byteArray,0,readLength);
readLength=inputStream.read(byteArray);
}
pngoutputstream.close();
inputStream.close();
socket.close();
serverSocket.close();
}
}
package com.company.s3;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket; public class Client {
public static void main(String[] args) throws Exception{
String pngFile="e:\\1.jpg";
FileInputStream pngstream=new FileInputStream(new File(pngFile));
byte[] byteArray=new byte[2048]; System.out.println("socket begin "+System.currentTimeMillis());
Socket socket=new Socket("localhost",8088);
System.out.println("socket end"+System.currentTimeMillis()); OutputStream outputStream=socket.getOutputStream(); int readLength=pngstream.read(byteArray);
while (readLength!=-1){
outputStream.write(byteArray,0,readLength);
readLength=pngstream.read(byteArray);
}
outputStream.close();
pngstream.close();
socket.close(); }
}

最新文章

  1. es6小白学习笔记(一)
  2. jquery 回到顶部,简洁大方
  3. iOS请求服务器数据去空NSNull
  4. F - Tree
  5. Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心
  6. Delphi下的RTTI函数大全
  7. ##DAY9 UITabBarController
  8. PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different
  9. Bayan 2015 Contest Warm Up D题(GCD)
  10. 设置Nginx+php-fpm显示错误信息
  11. C++中的继承(2)类的默认成员
  12. Mac_mac下使用ll等指令
  13. 一天一个Linux命令--dhclient
  14. Java 生态核心知识点整理
  15. About certificate
  16. springBoot(4)---热部署,配置文件使用
  17. [Day8] eclipse
  18. 转角遇见——Software
  19. Git与GitHub的基本使用
  20. day20 类的约束

热门文章

  1. python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决
  2. sleep方法要求处理中断异常:InterruptedException
  3. Windows密码获取和破解(初探)
  4. Android 开发凉了吗!
  5. django补充CBV和FBV模式
  6. laravel .env文件的使用
  7. Spring Cloud进阶之路 | 一:服务注册与发现(nacos)
  8. 【zabbix服务】修改zabbix_server默认端口号
  9. feign响应Image流对象
  10. 一个神奇的HTML标签-----marquee