我试图通过字节块一次将二进制文件从服务器传输到客户端。但是,我遇到了一个转移8kb的问题。该文件通常大于1mb,字节数组的大小为1024.我相信它必须对我的while循环做些什么,因为它没有关闭我的连接。任何帮助?谢谢
客户
import java.io.*;
import java.net.Socket;
public class FileClient {
public static void main(String[] argv) throws IOException {
Socket sock = new Socket("localhost", 4444);
InputStream is = null;
FileOutputStream fos = null;
byte[] mybytearray = new byte[1024];
try {
is = sock.getInputStream();
fos = new FileOutputStream("myfile.pdf");
int count;
while ((count = is.read(mybytearray)) >= 0) {
fos.write(mybytearray, 0, count);
}
} finally {
fos.close();
is.close();
sock.close();
}
}
}服务器
import java.net.*;
<