好吧,我一直在使用Jsoup来解析来自远程网址的html:
Jsoup.connect(url).timeout(20000).get();
Run Code Online (Sandbox Code Playgroud)
我现在正在尝试读取我存储在该assets文件夹中的本地html文件.我做了很多搜索,但我找不到解决方案.在Jsoup示例 - 从文件加载文档,他们说要执行以下操作:
File input = new File("/tmp/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Run Code Online (Sandbox Code Playgroud)
根据我的阅读,我的文件的路径将是 - file:///android_asset/results_2009.html.

但是我总是得到no such file or directory,所以如何将本地文件导入Jsoup?
我需要使用AssetManager什么?请有人指出我正确的方向.
Jsoup.parse()有一个带有InputStream的重载.您可以使用它AssetManager来获取InputStream文件并使用它:
InputStream is=null;
try {
is=getAssets().open("results_2009.html");
Document doc = Jsoup.parse(is, "UTF-8", "http://example.com/");
} catch (IOException e) {
e.printStackTrace();
} finally {
if(is!=null)
is.close();
}
Run Code Online (Sandbox Code Playgroud)