Sta*_*tan 9 android assets file
我想获取位于assets目录中的文件的文件大小.我看到很多例子
InputStream myInput = appContext.getAssets().open()
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过简单InputStream的循环读取来确定文件大小,但我正在寻找一种方法来做到这一点File object.
所以我需要一条通往资产的道路,这就是我无法确定的事情......如何获得这条道路?
也试过AssetFileDescriptor通过appContext.getAssets().openFd(),openNonAssetFd()但没有运气 - 得到FileNotFound或可能压缩的例外.
BTW那些openFd方法在developer.android.com上"很好地描述"了.
file = new File(new URI("file:///android_asset/db/call3.db"));
Log.i(APP_TAG, "File name: "+file.getName());
Log.i(APP_TAG, "File path: "+file.getPath());
Log.i(APP_TAG, "File length: "+file.length());
Log.i(APP_TAG, "File isFile: "+file.isFile());
Log.i(APP_TAG, "File exists: "+file.exists());
Run Code Online (Sandbox Code Playgroud)
输出到日志:
04-13 12:10:03.413:INFO(6259):文件名:call3.db
04-13 12:10:03.432:INFO(6259):文件路径:/android_asset/db/call3.db
04-13 12:10:03.444:INFO(6259):文件长度:0
04-13 12:10:03.444:INFO(6259):文件isFile:false
04-13 12:10:03.444:INFO(6259):文件存在:false
当然文件的大小不是0,它是195 584字节.
如何走这条路?
没有路径.抱歉,你所寻求的是不可能的.
| 归档时间: |
|
| 查看次数: |
5929 次 |
| 最近记录: |