企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
~~~ package com.youge.nio.zerocopy; import java.io.*; import java.net.Socket; /** * 传统的IO传输读写数据 * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com * @date: 2020/11/27 10:35 */ public class OldIOClient { public static void main(String[] args) throws IOException { Socket socket = new Socket("127.0.0.1", 7001); String fileName = "phpstudy_install.dmg"; InputStream fileInputStream = new FileInputStream(fileName); DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream()); byte[] buffer = new byte[4096]; long readCount; long total = 0; long startTime = System.currentTimeMillis(); while ((readCount = fileInputStream.read(buffer)) != -1) { System.out.println(readCount); total += readCount; dataOutputStream.write(buffer); } System.out.println("发送总字节:" + total + ",耗时:" + (System.currentTimeMillis() - startTime)); dataOutputStream.close(); fileInputStream.close(); socket.close(); } } ~~~