如何从android中的assets文件夹中读取html内容
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 (帕特纳)
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();
}
This is my code. I want to read html content from asstes folder my file is available in asstes folder But it gives exception FileNotFoundException
. So plz any one tell me how to read html content from asstes folder in android?
File f = new File( "file:///android_asset/[2011]011TAXMANN.COM00167(PATNA)") ;
when i debug f gives= file:/android_asset/[2011]011TAXMANN.COM00167(PATNA)
plz tell me how to get corrct directory and where i m doing wrong it shud me coming file:///android_asset/[2011]011TAXMANN.COM00167(PATNA)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是从 WebView 中的资源加载 HTML 文件的方法
Untitled-1.html---应首先保存为 .html 扩展名的文件名
已编辑
尝试此链接
http://developer.android.com/reference/android/content/res/AssetManager.html
这个文档有方法
公共最终字符串[]列表(字符串路径)
This is the way to load HTML file from assets in WebView
Untitled-1.html---File name that should be save first as .html extension
Edited
try this link
http://developer.android.com/reference/android/content/res/AssetManager.html
there is method from this doc
public final String[] list (String path)
您可以通过以下代码获取InputStream:
<代码>
getResources().getAssets().open("you_file_name_goes_here");
You cat get InputStream by this code:
getResources().getAssets().open("you_file_name_goes_here");
你不想用对
吗?
试试这个,我在博客中找到了它:
用法:
抱歉我的英语不好:)
you don't want to use
right?
try this i found it in a blog:
usage:
Sorry for my bad english :)