我使用以下代码将一个byte [] [] [] []对象写入文件:
byte[][][][] allMaps = new byte[10][8][][];
allMaps = ...;
ObjectOutputStream outputStream = null;
try {
outputStream = new ObjectOutputStream(new FileOutputStream("all_maps"));
outputStream.writeObject(allMaps);
} catch (IOException e) {
...
}
现在我正在尝试将那个 byte[][][][] 对象读入我的Android应用程序:
InputStream inputStream = getResources().openRawResource(
getResources().getIdentifier("raw/all_maps", "raw", getPackageName()) );
try {
byteMaps = (byte[][][][]) ((ObjectInputStream) inputStream).readObject();
} catch (OptionalDataException e) {
...
但是我遇到了这个错误(在以“byteMaps”开头的那一行):
java.lang.ClassCastException: android.content.res.AssetManager$AssetInputStream cannot be cast to java.io.ObjectInputStream
为什么
inputStream
的类型是AssetInputStream
而不是java.io.InputStream
?