Split and join back a binary file in java

后端 未结 7 835
闹比i
闹比i 2020-12-13 10:45

I am trying to divide a binary file (like video/audio/image) into chunks of 100kb each and then join those chunks back to get back the original file. My code seems to be wor

7条回答
  •  孤城傲影
    2020-12-13 11:24

    And for joining file, I put the names of all chunks in a List, then sort it by name and then run the following code:

    But your names are of the following form:

    newName = fname + ".part" + Integer.toString(nChunks - 1);
    

    Think carefully about what happens if you have 11 or more parts. Which string comes first in alphabetical order: ".part10" or ".part2"? (Answer: ".part10", since '1' comes before '2' in the character encoding.)

提交回复
热议问题