标签:class length inpu ack string cep system get except
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(); } }
标签:class length inpu ack string cep system get except
原文地址:https://www.cnblogs.com/guoyansi19900907/p/10977444.html