字节缓冲流需不需要刷新
import java.io.*;
import java.net.Socket;
class FileClient {
public static void main(String[] args)throws Exception{
File file = new File("e:\\1.jpg");
Socket s = new Socket("127.0.0.1",10120);
BufferedInputStream bis =new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());
System.out.println("afaafaf");
int b=0;
while((b=bis.read())!=-1){
out.write(b);
}
out.flush();//当不写这句时188k变成184k
s.shutdownOutput();
System.out.println("afaafaf");
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = in.readLine();
System.out.println(line);
bis.close();
s.close();
}
} |
|