【发布时间】:2011-01-15 10:03:09
【问题描述】:
我正在寻找一些简单的东西(最好没有外部库)来从文件中写入和加载 byte[]。或多或少类似于 [Python's pickle][1]。
byte[] bytes = new byte[10];
ByteBuffer bbuf = new ByteBuffer.allocate(bytes.length);
bbuf.wrap(bytes); // edited due to Jon Skeet's answer
CharBuffer cbuf = bbuf.asCharBuffer();
cbuf.put("t");
FileOutputStream test = new FileOutputStream("somebytes");
test.write(bytes);
test.close();
问题似乎是我无法从这样的文件中读取对象结构。此外,在十六进制编辑器中,文件“somebytes”仅包含一对或 0。因此,FileOutputStream 似乎没有将任何内容(“t”或等效字节)放入其中。
【问题讨论】:
标签: java standard-library object-serialization