如何判断assets下的某一个文件是否存在

2025-03-03 18:05:47
推荐回答(1个)
回答1:

* 加载本地图片
* @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