Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

creating DAT file  RSS feed

 
Gobind Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement to create a DAT file from data that I have already read in a java.sql.ResultSet.

I need to be able to write the data out to a .DAT file using the below format. (I am not a C programmer so I dont know how these type defs works)

typedef struct tagEntRecord
{
unsigned long code;
unsigned short pack_size:14;
unsigned short price_change:2;
unsigned short trade_price;
unsigned short retail_price;
char description[39];
char width;
}EntRecord


Can anyone explain to me how to go about doing this?
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"typedef struct" in C is similar to a class in Java in that it allows us to collect data into a structure that we can make sense of and manipulate. C does not have the feature of attaching methods to a data structure like object-oriented languages.
The first step you should take is identify how many bytes each of the fields in the struct is, as the data type sizes will probably differ from Java. If you are comfortable manipulating bytes, you can use a plain OutputStream to write your data. I would probably use a RandomAccessFile, as it has some handy methods for writing Java primitives.
 
Gobind Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I will try what you suggested.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!