Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading Binary

 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to read a binary file and convert it to a readable text? Thanks!!!
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each file has to be investigated to determine what classes and methods are best suited to read it. In general if the file is all text, Readers can easily be used to read the data. If the data is numeric saved in binary form, InputStream classes are best but, you may have to do some bit manipulation to determine the information it holds. While this question may seem easy, the only real answer is, check the type of data that the file contains and read the documentation to determine the best Class and methods to handle it. Sometimes this takes a little trail and error.
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carl,
Do you have any idea how to do the bit manipulation? I am using PrintWriter(FileWriter) to write a file to disk. Then, I use FileInputStream to read each byte back. When I write this, "Hello Test" and read it back, I get "72 101 108 108 111 32 84 101 115 116 13 10". I want to get this into chars, so that it will look exactly as it did when I wrote it to disk. I am not even sure if I am on the right track here or not, so if you can at least point me in the right direction. Thanks a lot!!!
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I am being stupid. There is no bit manipulation necessary. All I had to do was convert it to char. Thanks anyway!
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I meant above. The best way to read what you wrote is to use BufferedReader and the readLine() method which would return the String "Hello Test" without doing any conversuion.
Hope this helps
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but I think I am not being clear on exactly what I am trying to do. Actually, I do not know if it can be done. Maybe you can tell me. I am trying to convert .dll files to a readable text. Are dlls in binary? If so, can they be converted to text? The way I did it does not work, because I just get the original that I wrote to disk which is just a lot of squares with a little bit of text. Thanks for you help!!
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DLL's are Dynamic Link Libraries These are files that contain Executable code that is platform and operating specific. If you want to translate these to anything readable, you need to know every detail about these for the DLL in question.
Hope this helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!