• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read binary file line by line

 
yair fridman
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a binary file that has have a new line delimeter in each line
When i tried to use bufferedReader with readline method it failed to read the binary line correctly
How can i do it without reading each byte and compare it to new line char?
I need to read each line seperetly because each line represent a protobuf that i need to parse
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yair fridman wrote:
When i tried to use bufferedReader with readline method it failed to read the binary line correctly
How can i do it without reading each byte and compare it to new line char?


The BufferedReader class, is a Reader, and is used for character streams -- ie. streams that follow the Unicode standard. It is not designed for pure binary files.

Henry
 
yair fridman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i know that but i need to read the file line by line in some way , since this is how i get the file.

{binary data} \n
{binary data } \n
.....
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to read the file using an InputStream, scan the input for the newline character and when found pass that chunk of data back to your calling method. You could do this on the fly (ie as you read the file) or you could read the whole file in and then break it into chunks later (assuming the file will always be small enough to be read in one go).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!