阅读从资产的HTML文件 [英] Read HTML file from assets

查看:77
本文介绍了阅读从资产的HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的资产html文件,aaa.html。 我想读的HTML文件的内容,并从另一字符串替换。

时的这种方式是正确的,或是否有任何其他选项。

我的code:

 文件f =新的文件(文件:///android_asset/aaa.html);
的FileReader FR =新的FileReader(F);
的BufferedReader BR =新的BufferedReader(FR)
 

但它给人找不到文件,其中为加载Web视图中加载该文件。

解决方案

 的InputStream是= getAssets()开(aaa.html)。
INT大小= is.​​available();

byte []的缓冲区=新的字节[尺寸]
is.read(缓冲液);
is.close();

字符串str =新的String(缓冲区);
海峡= str.replace(老串,新建字符串);
 

I have an html file in assets, aaa.html. I want to read the contents of html file and replace it from another string.

Is this way is right or is there any other option.

my code:

File f = new File("file:///android_asset/aaa.html");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);

But its giving file not found, where as loading in web view loads the file.

解决方案

InputStream is = getAssets().open("aaa.html");
int size = is.available();

byte[] buffer = new byte[size];
is.read(buffer);
is.close();

String str = new String(buffer);
str = str.replace("old string", "new string");

这篇关于阅读从资产的HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆