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本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报