Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getting text out of a binary file  RSS feed

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys: I have a binary file, and I can succesfully read it. I have used the famous BinaryFile.java class http://www.heatonresearch.com/articles/22/page2.html

Anyways, this particular type of file has a 2048 byte header...Im trying to read the file using the following code, but am only getting numbers.



Obviously, I need a way to read these bytes in as letters... I have tried using the methods "readFixedString" "readFixedZeroString" and "readLengthPrefixString" all to no avail (they just return numbers usually 0).
Any ideas about whats going wrong ?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with that class but "new String(bytes,0,2048))" will only work if the file is encoded in the platform default encoding. If that is the case, and the header contains just characters, can't you just use a FileInputStream?
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the file was written by in binary by legacy C programs. That makes me assume that I won't be able to "luck out" in the sense that it probably isnt Unicode or whatever else my Mac OS X uses....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!