1

我在我的资产文件夹中包含了一些 html 文件,但是当我尝试在 web 视图中显示它们时,我收到了一个找不到文件的错误。我也无法在 fileexplorer 的 //data/data/files 文件夹中看到该文件。不知道是什么问题。任何人都可以帮忙吗?

4

2 回答 2

0

我展示了一个帮助文件,该文件是由我放在资产文件夹中的静态 html 文件驱动的。这是我的代码:

BufferedReader in = null; 
StringBuilder buffer = new StringBuilder();

String assetFile = "help.html";

try { 

    in = new BufferedReader(new InputStreamReader(getAssets().open( assetFile ),"utf-8")); 
    String line; 

    /* line by line read in the file */
    while ((line = in.readLine()) != null) buffer.append(line); 

} catch (IOException e) { 
} finally { 
    try { in.close(); } catch (Exception e) {} 
} 

WebView wv = (WebView) findViewById(R.id.help_view);
wv.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
wv.loadDataWithBaseURL(null, buffer.toString(), "text/html", "utf-8",null);
于 2013-02-22T14:56:22.363 回答
0

到目前为止,我不知道您尝试了什么,但这是在运行时从 assets 文件夹中获取文件的一种正确方法:

InputStream is = getAssets().open("YourHTML.html");
于 2013-02-22T14:54:33.777 回答