我有一个 java 可序列化对象,我想将该对象写入/读取文件。然而 Google 应用引擎不支持 fileoutputstream 和 objectoutputstream 所以我将可序列化对象转换为字节数组并将其写入文件
$FileWriteChannel writeChannel = fileService.openWriteChannel(
writableFile, lockForWrite);
$writeChannel.write(ByteBuffer.wrap(bytearray));
$writeChannel.closeFinally();
然后我读了文件:
AppEngineFile readableFile = new AppEngineFile(filename);
FileReadChannel readChannel = fileService.openReadChannel(readableFile, lockForRead);
BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF-8"));
String line = reader.toString();
我看到了日志,但出现了 UTF-8 错误 谁能告诉我我做错了什么?
错误日志:
cloud.spam.filter.server.SerializationObject file_io: An error message: invalid stream header: 5B4240312012/07/06 08:00:10
谢谢