💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ 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(); } } ~~~