我正在尝试获取位于assets
中的文件大小。
我使用FileChannel
是因为稍后需要一个FileChannel
。
文件myfile.txt
包含7个字节。
以下是我的代码:
AssetManager amgr;
AssetFileDescriptor afd;
FileChannel fchIn;
FileInputStream fis;
amgr=context.getAssets();
afd=amgr.openFd("myfile.txt");
fis=afd.createInputStream();
fchIn=fis.getChannel();
Log.d("mytag", fchIn.size());
Log.d("mytag", fis.available());
输出结果如下:
7237492
7
为什么FileChannel.size()
方法返回的大小是错误的?
谢谢您的帮助。