import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* 测试类, FileInputStream
* @author Administrator
*
*/
public class Test3 {
public static void main(String[] args) {
try {
//创建IO流对象
InputStream is = new FileInputStream("file/test.txt");
//显示文件的总字节数
System.out.println("总字节数量:" + is.available());
//创建字节数组, 存放文件内容
byte[] content = new byte[is.available()];
//将文件内容读取到数组中
is.read(content);
//打印
System.out.println(new String(content));
//关闭IO资源
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
file/test.txt 中的文件内容:
运行结果: