import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
public class Client {
public static void main (String [] args ) throws IOException {
int filesize=2022386;
int bytesRead;
int currentTot = 0;
Socket socket = new Socket("192.168.1.6",15123);
byte [] bytearray = new byte [filesize];
InputStream is = socket.getInputStream();
FileOutputStream fos = new FileOutputStream("d:\\copy.rar");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead = is.read(bytearray,0,bytearray.length);
currentTot = bytesRead;
do {
bytesRead =
is.read(bytearray, currentTot, (bytearray.length-currentTot));
if(bytesRead >= 0) currentTot += bytesRead;
} while(bytesRead > -1);
bos.write(bytearray, 0 , currentTot);
bos.flush();
bos.close();
socket.close();
}
}
上面是我的客户端代码,它以非常缓慢的方式从服务器读取数据你能否建议我提高传输速度。我可以使用这段代码阅读视频文件,如果不建议这样做的话。