2012-12-28 10 views
5

は、[OK]をよく私がJsoupを使用して、リモートのURLからHTMLを解析するために使用されているandroid_asset htmlファイルでJsoupを使用して:アンドロイド -

Jsoup.connect(url).timeout(20000).get(); 

私は今、私はassetsフォルダに保存されているローカルのHTMLファイルを読み込むしようとしています。私はたくさんの検索をしましたが、解決策を見つけることができません。 Jsoup example - Load a Document from a Fileでは、彼らは次の操作を実行するために言う:私は何を読んでから、

File input = new File("/tmp/input.html"); 
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); 

、私のファイルへのパスは次のようになり - file:///android_asset/results_2009.html

enter image description here

しかし、私はいつもno such file or directoryを取得するので、どのように私はJsoupにローカルファイルを入手できますか?

などを使用する必要がありますか?誰かが私を正しい方向に向けることができますか?

答えて

9

Jsoup.parse()は、overload which takes an InputStreamです。あなたは、あなたのファイルにInputStreamを取得し、それを使用するAssetManagerを使用することができます :S:

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(); 
} 
+0

は、私がJsoupのAPIドキュメントを読んでいる必要がありますね – Neil