I am reading a file into byte array, i have inserted some control command into it, which I need to decode in some other class. But how to identify and separate these information from rest of the content of file being read. I need to use some unique character as a delimiter to identify the start and end of this control command in the byte array. Is there any unique character which i can use for this purpose ? That particular character should not be present in any normal binary file of any format.
Share
No, by definition there is no such a control character. But what you can do is store the array in a format that follows: [length of byte array] [byte array]. All you have to do then is read in an integer <- the length, create a new array of that length and read it fully.
EDIT:
Okay so use the following format:
The file name is null terminated so you know the delimiter there (this works because a file name is ASCII only!). Then you have the length (an integer/long) and then the byte array.
All of the other methods mentioned above are unsafe and if you use a complex delimiter then: it’s not perfect and takes up more space then using the a simple length variable…