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.运行结果如下:

多出了红色框中的数据


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM