14K
14K

Reputation: 439

Reading binary file in Java

Let's say I want to read a binary file which contains three of data types char, int and double (However,this binary file can contain any number of these three data types in any order.). And then I want to store three of these data types to char array list, double array list and integer array list. Anyone could be able to help? I really appreciate it.

Upvotes: 0

Views: 536

Answers (2)

user207421
user207421

Reputation: 311050

The basic answer is DataInputStream. It has methods to read all the primitive datatypes. When you read which type is of course up to you :-)

Upvotes: 2

Eric
Eric

Reputation: 19873

Your file needs some kind of map on how to read it. There is no magic function that can distinguish between lets say 4 char and 1 int.

You need to open the file, read the map then read the file accordingly

Upvotes: 2

Related Questions