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.運行結果如下:
多出了紅色框中的數據