if ((new File("file://android_assets/aa.mp3")).exists()) {}
if ((new File("aa.mp3")).exists()) {}
以上方法都无法判断
如何判断assets下的某一个文件是否存在
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 东子哥7 2013-05-02 05:58关注
感谢以上两位朋友的回答,@franzhong的方式我用过,也是可以的
下面我用的方法,/** * 加载本地图片 * @param url * @return */ public static Bitmap getLoacalBitmapByAssets(Context c, String url) { Bitmap bitmap = null; InputStream in = null; try { in = c.getResources().getAssets().open(url); bitmap = BitmapFactory.decodeStream(in); } catch (IOException e) { e.printStackTrace(); } finally { closeStream(in, null); } return bitmap; } Bitmap bmp = getLoacalBitmapByAssets(getActivity(), strIconName); if (bmp!=null){ //如果返回的bmp不为空,表示存在这这个资源 ivIcon.setImageBitmap(bmp); //I
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机
- ¥20 程序进入HardFault_Handler
- ¥15 oracle集群安装出bug
- ¥15 关于#python#的问题:自动化测试