try {
File f = new File( "file:///android_asset/[2011]011TAXMANN.COM00167(PATNA)") ;
FileInputStream fis= new FileInputStream(f);
System.out.println("_______YOUR HTML CONTENT CODE IS BELLOW WILL BE PRINTED IN 2 SECOND _______");
Thread.sleep(2000);
int ch;
while((ch=fis.read())!=-1)
{
fileContent=fileContent+(char)ch; // here i stored the content of .Html file in fileContent variable
}
System.out.print(fileContent);
//}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是我的代码。我想从 asstes 文件夹中读取 html 内容,我的文件在 asstes 文件夹中可用,但它给出了异常 FileNotFoundException
。那么请有人告诉我如何从 android 中的 asstes 文件夹中读取 html 内容?
文件 f = new File("file:///android_asset/[2011]011TAXMANN.COM00167(PATNA)") ; 当我调试 f 时,给出= file:/android_asset/[2011]011TAXMANN.COM00167(PATNA)
请告诉我如何获取正确的目录以及我在哪里做错了,这让我感到震惊 file:///android_asset/[2011]011TAXMANN.COM00167(PATNA)
最佳答案
这是从WebView中的资源加载HTML文件的方法
webview.loadUrl("file:///android_asset/Untitled-1.html");
Untitled-1.html---应首先保存为.html扩展名的文件名
已编辑
试试这个链接
http://developer.android.com/reference/android/content/res/AssetManager.html
此文档中有方法 公共(public)最终字符串[]列表(字符串路径)
关于java - 如何从android中的assets文件夹中读取html内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8603222/