is there any method in java which would implement the same function as BinaryReader() in Visual C++
Asked
Active
Viewed 2,033 times
-1
-
Maybe check `BufferedReader`? – Buhake Sindi Jun 21 '12 at 13:39
-
@Gaara i m very new to programming. i have been searching for a method to read a binary file in which numerical data,( floating point data both positive and negative) is stored in 16 bit form. now, i have been researching a lot but somehow i have not been able to do that. every time i am getting wierd results. I am running short on time, so please don't get irritated and help me. – Chetan Gupta Jun 21 '12 at 14:30
3 Answers
0
public interface DataInput
The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of the Java primitive types.
All Known Implementing Classes: DataInputStream, ImageInputStreamImpl, ImageOutputStreamImpl, ObjectInputStream, RandomAccessFile
Also, you are looking for a Class in Java, not a method (as BinaryReader is a Class and not a function in C++)

Chris Dargis
- 5,891
- 4
- 39
- 63
0
I had a need for this and wrote an equivalent class.
https://gist.github.com/vangorra/9470810
It is essentially an implementation of .Net's BinaryReader in java. It does not have every method implemented, but provides a good start for anybody who needs to go down this path.
Example of what this class can do:
BinaryReaderDotNet reader = new BinaryReaderDotNet(new FileInputStream(new File("blah.bin")));
reader.readInt32(); // returns int
reader.readUInt32(); // returns long
reader.readInt16(); // returns int (first bits are zeroed)
reader.readUInt16(); // returns int (first bits are zeroed)
reader.readString(); // returns a string.
reader.readBoolean(); // returns a boolean
reader.readSingle(); // returns a float

vangorra
- 1,631
- 19
- 24