FIleInputStream中方法
int available();返回流当中剩余的没有读到的字节数量
long skip(long n);跳过几个字节不读
一个字节的读取效率慢。硬盘和内存交互太频繁,浪费资源。(推荐下面)
package com;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class test {
public static void main(String[] args) {
FileInputStream fis = null;
try {
fis = new FileInputStream("D:\\test.txt");
//死循环去读
/* while (true) {
int read = fis.read();
if (read == -1) {
break;
}
System.out.println(read);
}*/
//改造while
int readData=0;
while ((readData = fis.read())!=-1){
System.out.println(readData);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//关闭流
//关闭流的前提是:流不是空,流是null没必要关闭
if (fis != null) {
//避免空指针异常
t