Ok well I have been using Jsoup to parse html from remote urls using:
Jsoup.connect(url).timeout(20000).get();
I am now trying to read local html files which I have stored in the assets
folder. I have done a lot of searching but I cannot find a solution. On the Jsoup example - Load a Document from a File, they say to do the following:
File input = new File("/tmp/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
From what I've read, the path to my file would be - file:///android_asset/results_2009.html
.
However I always get no such file or directory
, so how do I get a local file into Jsoup?
Do I need to use AssetManager
or something? Please can someone point me in the right direction.
Jsoup.parse()
has an overload which takes an InputStream.
You can use the AssetManager
to obtain an InputStream
to your file and use it:
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With