我已经实现了一个在我的计算机上运行的数据结构,现在我正在尝试将其移植到我的
Android应用程序中.我打开一个原始.dat资源并获取一个InputStream但我需要获取一个FileInputStream:
FileInputStream fip = (FileInputStream) context.getResources().openRawResource(fileID);
FileChannel fc = fip.getChannel();
long bytesSizeOfFileChannel = fc.size();
MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0L, bytesSizeOfFileChannel);
...
上面的代码抛出以下异常,因为无法将InputStream强制转换为FileInputStream,但这正是我需要的:
java.lang.ClassCastException: android.content.res.AssetManager$AssetInputStream cannot be cast to java.io.FileInputStream
我的所有代码都是使用FileChannel和FileInputStream构建的,所以我想继续使用它.有没有办法从context.getResources().openRawResource(fileID)获得一个InputStream,然后将其转换为FileChannel?
一些相关的帖子,我找不到一个工作的解决方案,我的情况下android: