• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Binary File Parsing

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have one binary file (.dat). I have to parse that file. So, can anyone suggest me how I can achieve this?

Is there any 3rd party API available like for XML I am using VTD-XML parsing ?

Thanks!!!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what the connection to XML might be, but if you don't have a library that can handle whatever format the file has, you'll need to write a parser based on the java.io classes (like FileInputStream).
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What information do you have on the structure of the data? What generates your .dat file?

Bill
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:What information do you have on the structure of the data? What generates your .dat file?

Bill



binary files are coming from the hardware device. I have a file named xyz.dat which contains lines like below

00000000h: 76 04 00 01 00 FF 0F 11 FF 09 07 03 15 ; v....

this is a kind of lines in my file above is not complete line

can anyone suggest how can I parse this kind of files???

Thanks!!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Ulf suggested, you can read the contents of a binary file using FileInputStream. What you should then do with the bytes that you read, entirely depends on what the format of the file is and what your program needs to do with it. Without knowing what the bytes in the file mean, you can't do anything useful with it and nobody can tell you. You should lookup documentation of the device to find out what the format of the file is.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When parsing a byte[] remember that any operation looking at a byte is going to automatically promote the value to a signed int so your FF byte will become -1.

Therefore, use a bitwise mask with 0xFF before checking the value.

Bill
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic