Splitting Binary files and adding data to each chu

2019-08-28 04:23发布

I have to work on a project in which I have to convert a binary file into a custom file format, which requires splitting the file adding some data to it and then repacking it into the new file.

For Example

I have a file of 1 MB and I have to split it into chunks of fixed length and then adding some data as a header to it. After that the entire file will be repackaged into a new file.

Please any help will be appreciated.

1条回答
Emotional °昔
2楼-- · 2019-08-28 04:43

First you use a DataInputStream to read chunks of x bytes into individual byte arrays, where x is your chunk size. I would suggest to store these byte arrays in an ArrayList.

Then you create a DataOutputStream for creating the new file.

Finally, you iterate over your ArrayList with a for loop and write the contents of the arrays to the DataOutputStream, preceded or followed by the additional data you need to add for each chunk.

I hope I was able to help you. When something is unclear, feel free to ask.

查看更多
登录 后发表回答