FileInputStream的available方法
available():返回与之关联的文件的字节数
import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class FileInputStreamDemo2 { public static void main(String[] args) throws IOException { // File file = new File("D:\传智播客毕向东java\解压后mp4文件\day22_mp4-IO流\IO流\19-IO流-字节流-复制图片图解.mp4"); // System.out.println(file.length()); FileInputStream fis = new FileInputStream("tempfile\fos.txt"); // System.out.println(fis.available());//可以获取与之关联的文件的字节数 byte[] buf = new byte[fis.available()]; //创建了一个和文件大小一样的缓冲区,刚刚好 fis.read(buf); System.out.println(new String(buf)); fis.close(); } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。