现在,I#m试图编写一个读取..cdr文件的程序。CDR的格式如下所示:
***************
* File header *
***************
File length: 44142 bytes
Header length: 54 bytes
High release identifier: Check the field extension below
High version identifier: Version 6
Low release identifier: Check the field extension below
Low version identifier: Version 6
File opening local timestamp: May 20 00:28 (+02:00 from UTC)
Timestamp of last CDR on file: May 20 01:28 (+02:00 from UTC)
Number of CDRs in the file: 130 CDRs
File sequence number: 386
File closure trigger reason: File open-time limit reached
IP address of node generating the file: ff.ff.ff.ff::ffff:ac10:1438
Lost CDR indicator: 0 CDRs lost
Length of CDR routeing filter: 0 bytes
Length of private extensions: 0 bytes
High release ID extension: Release 13
Low release ID extension: Release 13这是我的密码:
可读性-方法:
public Collection<Data> readBinary(String file) throws IOException, FileNotFoundException
{
ArrayList<Data> arrayList=new ArrayList<>();
try(DataInputStream dis=new DataInputStream(new BufferedInputStream(new FileInputStream(file))))
{
while (dis.available()>0)
{
arrayList.add(new Data(dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(),dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readInt(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF()));
}
}
return arrayList;
}主要:
public class Main implements Serializable
{
public static void main(String[] args) throws IOException, ClassNotFoundException {
Methoden m = new Methoden();
try {
ArrayList<Data> d1 = (ArrayList<Data>) m.readBinary("172.16.20.5601_-_386.20210520_-_0128+0200.cdr");
System.out.println(d1);
} catch (IOException e) {
e.printStackTrace();
}
}
}所以我的问题是,当我运行这个程序时,我得到了一个EOFException,我不明白为什么..。
也许有人能帮我解决我的问题
发布于 2022-03-02 17:44:25
您需要读取的第一件事是文件头中的文件长度字段。这可能是一个字节或两个字节-检查您的规范。看起来,您正在使用DataInputStream.readUTF阅读该字段,这对于阅读这样的字段是不合适的。
您需要根据文件布局进行读取。您似乎没有遵循文件布局,因此碰巧试图读取比您应该读取的更多的数据,因此出现了例外。
https://stackoverflow.com/questions/71319900
复制相似问题