标签:
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));
}
}
使用Java FileInputStream读取文件内容到字节数组中
标签:
原文地址:http://my.oschina.net/zzw922cn/blog/486990