A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王国华 中级黑马   /  2012-3-29 11:39  /  1523 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

字节缓冲流需不需要刷新
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();
       
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马