import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
/**
* TCP字符流上传文件并接受服务器反馈
*/
public class ClientDeom {
public static void main(String[] args) throws IOException {
/**
* 创建Socket对象
*/
Socket socket = new Socket(InetAddress.getLocalHost(), 10010);
/**
* 创建字节缓冲输入流并指向上传文件
*/
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("Array/src/Day12/Text07/ServerDeom.java"));
/**
* 获取字节输出缓冲流
*/
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
/**
* 向服务器发送数据
*/
int len;
byte[] bytes = new byte[1024];
while ((len = bis.read(bytes)) != -1) {
bos.write(bytes, 0, len);
bos.flush();
}
/**
* 标记发送完毕
*/
socket.shutdownOutput()
多线程上传文件
最新推荐文章于 2024-11-21 09:59:30 发布