View Single Post
  #1 (permalink)  
Old 01-08-2008, 08:57 AM
janakiram.attuluri janakiram.attuluri is offline
Member
 
Join Date: Dec 2007
Posts: 6
janakiram.attuluri is on a distinguished road
Reading a Field in a Binary File
Hi All,

I have a binary file to read which contains the fields i specified in FileStructure. I read tht using DataInputStream.

example i gave u only some fields but there are 150 fields r thr those r short int and char[] s.

wht is the way of reading tht. output should print the values of variables i specified in the constructor.

class FileStructure I used only for ur reference. data i hav to read from binary file.




Class FileStructure
{
short aaaaa;
short bbbbb;
int ccccc;
int ddddd;
int eeeee;
char[] ffffff[2];
short gggg;

public FileStructure()
{
aaaaa= 640;
bbbbb= 304044;
ccccc=0;
ddddd=0;
eeeee=0;
gggg=0;
}
}
public class ReadFile
{
public static void main(String args[])
{
File f=new File("C:\\Documents and \\VRP_U071201092710OSS00012.DAT");
FileInputStream in = new FileInputStream(f);
DataInputStream dataInputStream = new DataInputStream(in);

short s=dataInputStream.readShort();
short s1=dataInputStream.readShort();
// how to loop this thr r multiple short and ints and char[] are thr.
}
}

Last edited by janakiram.attuluri : 01-08-2008 at 01:25 PM.
Reply With Quote
Sponsored Links