Read First 4 Bytes of File
java
Solution
Like that :
byte[] buffer = new byte[4];
InputStream is = new FileInputStream("somwhere.in.the.dark");
if (is.read(buffer) != buffer.length) {
// do something
}
is.close();
// at this point, the buffer contains the 4 bytes...
Problem
I'm used to C#, but I'm trying to make an app which reads the first 4 bytes into an array, but I have been unsuccessful. I also need to reverse the Endian on the file which I don't know how in Java, in C# it is `Array.Reverse(bytes);`. I've tried reading the file into an Int32, but from there I cannot get it into an array for some reason.