dcsimg
How can I map 100 bytes read from file onto 100 bytes of a Java object's instance variables?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Philip_Chang
Posted On:   Friday, June 8, 2001 08:02 AM

How can I map 100 bytes read from file onto 100 bytes of a Java object's instance variables? class MyRecord { byte fielda[5]; byte fieldb[2]; byte fieldc[17]; byte fieldd[6]; byte fielde[70]; } I really don't want to do an assignment statement for every single instance variable. In C++, I would have coded: char bytes100[100]; read( filePtr, bytes100, 100 ); MyRecord *pMyRecord = (MyRecord*)bytes100;    More>>

How can I map 100 bytes read from file onto 100 bytes of a Java object's instance variables?



class MyRecord {

byte fielda[5];

byte fieldb[2];

byte fieldc[17];

byte fieldd[6];

byte fielde[70];

}



I really don't want to do an assignment statement for every single instance variable.



In C++, I would have coded:



char bytes100[100];

read( filePtr, bytes100, 100 );

MyRecord *pMyRecord

= (MyRecord*)bytes100;


   <<Less

Re: How can I map 100 bytes read from file onto 100 bytes of a Java object's instance variables?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Friday, June 8, 2001 08:53 AM

Philip,

You could probably use the reflection classes to do that. I don't understand why your class can have just a single byte[] member, like someone has already pointed out in the other message you've post. I don't see any difference in having 100 byte fields or one byte[]... it will make assignment a piece of cake.
About | Sitemap | Contact