我在Java中有一个带字节数组的类.当我序列化和反序列化类的对象时,字节数组的值正在改变.
我该如何解决这个问题?
请参阅示例代码:
public class Test implements Serializable{
private static final long serialVersionUID = 3455892176538865707L;
public byte[] datakey;
public static void main(String[] args) {
byte[] key=new byte[16];
Random rn = new Random(); //Trying to randomize the byte array to use as a cryptographic key
rn.nextBytes(key);
Test test = new Test();
test.datakey=key;
System.out.println("Byte Array Before serialization : "+test.datakey);
test.serializeTest(test);
Test loadedtest=test.deserializeTest();
System.out.println("Byte Array After deserialization : "+loadedtest.datakey);
}
public void serializeTest(Test test)
{
FileOutputStream fos;
try {
fos = new FileOutputStream("test.out"); …Run Code Online (Sandbox Code Playgroud)