Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Byte Array Questions

  Asked By: Dukker    Date: May 07    Category: Java    Views: 823
  

I'm new to java programming, new to this list, and I'm coming from a
c\c++ background. I'm having an issue with this lack of pointers in
java. What I want do is read in a structure from a file into a byte
array and then access each element based on type. Example:

C Structure
struct SomeStructure {
DWORD Member1;
DWORD Member2;
int Member3;
}

Java

// Open our file for reading
FileInputStream fileIn = new FileInputStream("Somefile");
byte inBuffer[] = new byte[10]; // Size of the structure

// Now read our structure into the buffer
fileIn.read(inBuffer);

So far this works. I could do a System.out.println on the byte array
to tell that the data is in there. But here is my problem.

// Define an integer to access the DWORD values
int Member1 = 0;
int Member2 = 0;

Member1 = inBuffer[0];
Member2 = inBuffer[4];

This doesn't work for some reason. It looks like it is only reading
the first byte that I point to. I hope this will help you determine
my problems.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Byte Array Questions Or get search suggestion and latest updates.




Tagged: