如何从文件读取字节,并将其放入字节数组而不将字节转换为整数?
答案 0 :(得分:1)
FileInputStream fis = new FileInputStream("your file name");
byte[] bytes = new byte[100]; // replace 100 with the desired size, of course
int offset = 0; // which element to stuff the byte into
fis.read(bytes, offset, 1); // the 1 is how many bytes to read
答案 1 :(得分:0)
byte ch;
try {
is = new DataInputStream(new FileInputStream("fileName.dat"));
while (true) {
ch = is.readByte();
// put here in any byte array ...
System.out.flush();
}
}