Java 读取一个二进制文件

来源:百度知道 编辑:UC知道 时间:2024/06/01 07:37:21
要求:一次读25字节 这25字节是以55 AA 开头的

public static final int PKGLENGTH = 25;
private byte[] data = new byte[23];
DataInputStream DataIN;
byte[] getData(){
//you read data code
return data;
}
在其他内中可以这样调用
int y=getData()[5];

各位达人帮帮忙 急用

//you read data code
File obfile = new File("test.dat");//二进制文件名:test.dat
BufferedInputStream instream;
try {
instream = new BufferedInputStream(new FileInputStream(obfile));
try {
instream.read(data, 2, 23);
instream.close();
} catch (IOException ex) {
}
} catch (FileNotFoundException ex) {
}