使用read()方法取一个字节数组的数据
package Reading;
/* 一次抛出一个字节数组
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class er { public static void main(String[] args) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream("fors.txt"); } catch (FileNotFoundException e) { e.printStackTrace(); } //定义一个字节数组 byte[] bys = new byte[1024]; int len; while((len = fis.read(bys)) != -1){ System.out.print(new String(bys,0,len)); } }
}