【发布时间】:2012-07-12 03:18:36
【问题描述】:
我得到了这个客户端应用程序,它将我的文件完全发送到服务器。但我希望它分块发送文件。这是我的客户端代码:
byte[] fileLength = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
dis.readFully(fileLength, 0, fileLength.length);
OutputStream os = socket.getOutputStream();
//Sending size of file.
DataOutputStream dos = new DataOutputStream(os);
dos.writeLong(fileLength.length);
dos.write(fileLength, 0, fileLength.length);
dos.flush();
socket.close();
那么我怎样才能让客户端分块发送我的文件呢?提前致谢。
【问题讨论】:
-
为什么要分块数据?当事先不知道要传输的数据长度时,一般使用 Chunk。
-
我正在尝试发送大文件
-
另外,由于您使用的是原始套接字,如果您对数据进行分块,服务器端应该知道这一点,否则,请使用标准 HTTP 协议。
-
@Santosh 我认为他只是使用了错误的标题。它不是分块发送,而是分块读取文件。
-
我的服务器已经分块读取数据,我需要在发送之前将文件切成块,因为我不能这样发送大文件
标签: java