Best way to read structured binary files with Java

前端 未结 12 918
我寻月下人不归
我寻月下人不归 2020-12-04 13:23

I have to read a binary file in a legacy format with Java.

In a nutshell the file has a header consisting of several integers, bytes and fixed-length char arrays, f

12条回答
  •  执笔经年
    2020-12-04 13:49

    You could use the DataInputStream class as follows:

    DataInputStream in = new DataInputStream(new BufferedInputStream(
                             new FileInputStream("filename")));
    int x = in.readInt();
    double y = in.readDouble();
    
    etc.
    

    Once you get these values you can do with them as you please. Look up the java.io.DataInputStream class in the API for more info.

提交回复
热议问题