检查android资产文件夹html文件的存在

我将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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...