gpt4 book ai didi

android - 检查是否存在 android Assets 文件夹 html 文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:52 26 4
gpt4 key购买 nike

我将 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 - 检查是否存在 android Assets 文件夹 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14660427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com