简体   繁体   English

Android中找不到文件错误

[英]File not found error in Android

I have two folders inside my assets folder which contains 3 html files. 我的资产文件夹中有两个文件夹,其中包含3个html文件。 I am loading one of this HTML file in a webview and inside this file I am referring other two files using href. 我正在Webview中加载此HTML文件之一,并且在此文件中,我使用href引用其他两个文件。 When I run this code and click on this link inside the webview I am getting an error in the webview that It cannot find the file. 当我运行此代码并单击Web视图内的此链接时,我在Web视图中收到错误消息,它找不到文件。 How should I give the path of the file. 我应该如何给出文件的路径。 I am just giving the file name only because it is in the same path as the referring HTML file. 我只给出文件名是因为它与引用HTML文件位于同一路径中。 What am I doing wrong? 我究竟做错了什么?

This is inside my html file. 这在我的html文件中。

 Functions <a href="android.resource://com.com.com/assets/begin.html">begin()</a> 
<a href="android.resource://com.mypack.test/assets/begin.html">begin()</a>

<a href="file:///android_asset/begin.html">begin()</a>

I tried both didn't work 我试过都没用

I am trying to get the begin.html file. 我正在尝试获取begin.html文件。

This is my java code 这是我的Java代码

 WebView web = (WebView)findViewById(R.id.webview);
        String str = readFile(parent_folder +"/"+ folder_name);
        web.loadData(str, "text/html", null);

readFile() reads the HTML file and returns the contents. readFile()读取HTML文件并返回内容。

inside this webview I am linking to another html file inside the assets folder. 在此Web视图中,我链接到资产文件夹中的另一个html文件。

android.resource://com.com.com/assets/file

use the above file path as uri to load the file if you have no folders in asset folder. 如果资产文件夹中没有文件夹,请使用上述文件路径作为uri来加载文件。 Better if you keep the files in raw folder and use it as 如果将文件保留在原始文件夹中并将其用作

android.resource://com.com.com/raw/filename

Note:: com.com.com is your package name 注意: com.com.com是您的软件包名称

Refer this LINK for usage of file from assets folder 请参考此链接以使用资产文件夹中的文件

Updated:: 更新::

   WebView web = (WebView)findViewById(R.id.webview);
   Uri path = Uri.parse("android.resource://com.com.com/raw/filename");
   web.loadUrl(path);//may need to convert uri to string

查看是否可行:

<a href="file:///android_asset/begin.html">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM