Before de serialising the file back into an object instance, I want to maliciously edit the txt in the file.
//Before
¨Ìsr&Snippets.Parsed.EmployeeSerialization0I
bankBalanceLnametLjava/lang/String;xp•Åt
Henry Crappe
//After
ÔøΩÔøΩsr&Snippets.Parsed.EmployeeSerialization0I
bankBalanceLnametLjava/lang/String;xpÔøΩÔøΩt
Fsekc Dhdhfie
However the edited file isn't correct and has some unusual characters.
//Before ¨Ìsr&Snippets.Parsed.EmployeeSerialization0I bankBalanceLnametLjava/lang/String;xp•Åt Henry Crappe //After ÔøΩÔøΩsr&Snippets.Parsed.EmployeeSerialization0I bankBalanceLnametLjava/lang/String;xpÔøΩÔøΩt Fsekc Dhdhfie
I'm guessing there is some sort of non readable character issue or something?
A file which contains a serialized object instance is a binary file: you should not edit it with a BufferedWriter. Edit it with a RandomAccessFile, for example.
If you are wondering of why, the charset used in a Writer could not map one-to-one with a byte. Saving all the file would change also unexpected positions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.