2025-03-30 05:21:26
读入时使用ByteArrayOutputStream缓存,然后转成byte[]
import java.io.*;
public class ReadFileBytes{
public static void main(String arg[]) throws FileNotFoundException, IOException{
Integer g[] = new Integer [60];
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileInputStream fin = new FileInputStream("ReadFileBytes.java");
int read;
byte[] bytes=new byte[1024];
while((read = fin.read(bytes)) >0){
out.write(bytes, 0, read);
}
fin.close();
bytes = out.toByteArray(); // 这就是全部的字节数组了。
out.close();
System.out.println(bytes.length);
}
}
2025-03-30 04:53:17
2025-03-30 02:00:08