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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Camwly 中级黑马   /  2015-11-28 21:06  /  879 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

文件a.txt中的内容是“大家好才是真的好”,然后我用代码读取并打印出来,结果是“大家好才是真的好真”,最后多了个“真”啊。
public static void main(String[] args) {
        FileInputStream fis=null;
        try {
                fis=new FileInputStream(new File("a.txt"));
                byte[] buff=new byte[6];
                int len=0;
                while((len=fis.read(buff))!=-1)
                {
                        String input=new String(buff);
                        System.out.print(input);
                }
        } catch (Exception e) {
                e.printStackTrace();
        }finally{
                try {
                        fis.close();
                } catch (IOException e) {
                        e.printStackTrace();
                }finally{fis=null;}
        }
}

1 个回复

倒序浏览
一次读1024个 就没问题了 至于多了个真 刘意老师java基础第20天有详细的解释
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马