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