0

I want to write a simple java program that reverses all the bytes of a file. It should corrupt the file by encoding and make it accesible after decoding. Is there something I need to be aware of?

I'm asking this because I wrote a program like that in the past and it didn't work, because after decoding the file was still corrupted. Is there something I have to keep in mind like a header portion of the file or something?

4
  • Have you tried actually comparing the contents of working original and non-working "decoded" files? (With a hex editor, for example?)
    – user1686
    Aug 1 '19 at 12:28
  • 1
    reverses all the bytes of a file Reverses the bytes in the file (first became last, second - pre-last, and so on...) or reverses bits in each separate byte? Is there something I need to be aware of? The most dangerous is "break in the middle".
    – Akina
    Aug 1 '19 at 12:30
  • @grawity a hex editor is a pretty good idea. Thanks for that! Aug 1 '19 at 12:35
  • Like @Akina said, despite whatever issues you are having, if you are not accounting for interruptions in the “encoding” and “decoding” process you will corrupt the file. What happens if you encode only half the file and the program crashes? Do you have a method of knowing where the program left off? Otherwise you’re screwed. You need to flip the bits, confirm the flip, then update a pointer with that position. Aug 1 '19 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.