机器人:检查文件是否存在在应用程序 [英] android: Check the existence of a file in the application

查看:175
本文介绍了机器人:检查文件是否存在在应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序文件夹中的资产很少的HTML文件。我的应用程序加载取决于设备的语言这些文件。当我检查它说,不存在,但是当我使用加载browser.loadUrl(文件名),该文件的文件是否存在等,它加载它的罚款。

I have few html files in assets folder of my application. My application loads these files depending on the device language. When I check for the existance of the file it say does not exist, but when I load that file using browser.loadUrl(filename), it loads it fine.

继code可以帮助你理解我的问题:

Following code will help you to understand my problem:

 String filename="file:///android_asset/actualfilemname.html";  
 File f = new File(filename);  
 if(!f.exist){  
    filename = "file:///android_asset/newfile.html";[Everytime it loads this file even though I have actualfilename.html in the folder]  
 }  
 browser.loadUrl(filename);

[它加载newfile.html但不actualfilename.html]

[it loads the newfile.html but not actualfilename.html]

推荐答案

您不能使用文件资源。你需要使用 AssetManager

You can't use File for resources. You'll need to use the AssetManager for that.

(在关闭的机会,文件并处理资源,我不认为是这样,你必须将路径转换为 URI 首先,例如使用 URI.create()。文件(字符串)预计的路径,而不是一个URI)。

(In the off-chance that File does handle resources, which I don't think it does, you'll have to convert the path to a URI first, for example using URI.create(). File(String) expects a path, not a URI.)

这篇关于机器人:检查文件是否存在在应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆