package date0802; import java.io.FileInputStream; import java.io.IOException; public class InputStream { @SuppressWarnings("resource") public static void main(String[] args) throws IOException { FileInputStream fileInputStream = new FileInputStream("1.txt"); //获取文件大小字节 int length=fileInputStream.available(); //读取文件字节到一个数组中 int bytesRead=0; int bytesToRead=length; byte[] input=new byte[bytesToRead]; while(bytesRead<bytesToRead) { int result=fileInputStream.read(input,bytesRead,bytesToRead-bytesRead); if(result==-1) break; bytesRead+=result; } fileInputStream.close(); System.out.println((bytesRead==length)); } }
时间: 2024-11-17 04:11:58