【发布时间】:2015-10-19 17:10:53
【问题描述】:
我正在尝试将字节数组写入文件,然后再次读取。问题是我读的字节数组和我写的不同。 下面代码的输出是:
[B@21a06946(原始字节数组写入)
[B@2fc14f68(字节数组读取)
byte[] encryptedKey = rsaCipher.encrypt(AESKey, publicKeyPathName, transformation, encoding);
System.out.println(encryptedKey);
List<byte[]> list = new ArrayList<byte[]>();
list.add(encryptedKey);
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("encryptedKey"));
out.writeObject(list);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream("encryptedKey"));
List<byte[]> byteList = (List<byte[]>) in.readObject();
in.close();
byte[] encryptedKey2 = byteList.get(0);
System.out.println(encryptedKey2);
【问题讨论】:
-
实例不同,但是你检查过内容吗?
-
这不是您检查数组相等性的方式,请改用 Arrays.equals(byte[]1,byte[]2)
-
当你看到像
[B@...这样的字符串时,你应该注意到它是一个变量引用而不是它的内容。[代表数组,B代表byte和@...代表“at ...”。
标签: java byte inputstream outputstream