【发布时间】:2015-08-30 18:40:31
【问题描述】:
我的应用程序读取一个类似 png 的文件(以字节为单位)并将字节存储到一个 byteArray 中。 这是我使用的方法:
public static byte[] read(File file) throws IOException {
byte []buffer = new byte[(int) file.length()];
InputStream ios = null;
try {
ios = new FileInputStream(file);
if ( ios.read(buffer) == -1 ) {
throw new IOException("EOF reached while trying to read the whole file");
}
} finally {
try {
if ( ios != null )
ios.close();
} catch ( IOException e) {
}
}
return buffer;
}
之后,我想提取那个 byteArray 的模式。
它遵循 png 文件的模式:
4 字节长度 + 4 字节类型 + 数据(可选)+ CRC 并重复该方案。
我想做类似 do while 的事情:读取长度 + 类型。如果我对类型不感兴趣,我想跳过那个块。 但我很挣扎,因为我找不到任何 skip 方法 用于 byteArray[]。
有人知道如何进行吗?
【问题讨论】: