When I directly copy the content of my html file and store it in a string, then show it in webview using:
mWebView.loadDataWithBaseURL("file:///android_asset/", myString, "text/html", "UTF-8", null);
everything is OK! I want to modify content of my html file (programmatically) before loading to webview, but when I read the html file from asset folder using below code
private String loadAssetTextAsString(Context context, String name) {
BufferedReader in = null;
try {
StringBuilder buf = new StringBuilder();
InputStream is = context.getAssets().open(name);
in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String str;
boolean isFirst = true;
while ( (str = in.readLine()) != null ) {
if (isFirst)
isFirst = false;
else
//buf.append('\n');
buf.append(str);
}
return buf.toString();
} catch (IOException e) {
Log.e("TAG", "Error opening asset " + name);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("TAG", "Error closing asset " + name);
}
}
}
return null;
}
and then load it in webview, the webview unexpectedly shows � character (I think its name is soft hyphen). I have used UTF-8 as charset in my html file. Also I have used below code for removing � which failed.
myString = myString.replace("�", "");
How can I remove �? thanks for any help.