InputStream中read方法各个参数的意义

1. 11.txt文件内容如下:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

2. 程序如下:

package com.xuzhiwen.io1;

import java.io.File;
import java.io.FileInputStream;

public class InputStreamTest {
    public static void main(String[] args) throws Exception {
        String s = File.separator;
        File file = new File("E:"+s+"filetest"+s+"11.txt");
        FileInputStream in = new FileInputStream(file);
        int len;
        byte b[] = new byte[1024];
        while((len = in.read(b, 0, b.length)) !=-1){
            System.out.println(new String(b));
        }
    }
}

3.运行结果如下:

4.修改红色字体代码

package com.xuzhiwen.io1;

import java.io.File;
import java.io.FileInputStream;

public class InputStreamTest {
    public static void main(String[] args) throws Exception {
        String s = File.separator;
        File file = new File("E:"+s+"filetest"+s+"11.txt");
        FileInputStream in = new FileInputStream(file);
        int len;
        byte b[] = new byte[1024];
        while((len = in.read(b, 0,20)) !=-1){
            System.out.println(new String(b));
        }
        in.close();
    }
}

5.运行结果如下:

多出了红色框中的数据

posted @ 2017-08-14 16:04  beibidewomen  阅读(2131)  评论(0编辑  收藏  举报