
我将HTML文件传递为“file:///android_asset/WebApplication/index.HTML”.如何在androID中检查此文件是否存在.
解决方法:
您可以尝试打开流,如果它失败,文件就不存在,如果它没有失败,文件应该在那里:
/** * Check if an asset exists. This will fail if the asset has a size < 1 byte. * @param context * @param path * @return TRUE if the asset exists and FALSE otherwise */public static boolean assetExists(Context context, String path) { boolean bAssetok = false; try { inputStream stream = context.getAssets().open(ASSET_BASE_PATH + path); stream.close(); bAssetok = true; } catch (fileNotFoundException e) { Log.w("IoUtilitIEs", "assetExists Failed: "+e.toString()); } catch (IOException e) { Log.w("IoUtilitIEs", "assetExists Failed: "+e.toString()); } return bAssetok;} 总结 以上是内存溢出为你收集整理的检查android资产文件夹html文件的存在全部内容,希望文章能够帮你解决检查android资产文件夹html文件的存在所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)