黑马程序员技术交流社区

标题: 关于字节缓冲流的一点疑问 [打印本页]

作者: 王国华    时间: 2012-3-29 11:39
标题: 关于字节缓冲流的一点疑问
字节缓冲流需不需要刷新
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();
       
        }
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2