Android ~ load Assets html file for WebView

mWebView = (WebView) findViewById(R.id.WebView01);

// read html from assets and assign to WebView
AssetManager assets = getAssets();
try {
InputStream is2 = assets.open("order.html");

BufferedReader in = new BufferedReader(new InputStreamReader(is2));
StringBuffer buffer = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
buffer.append(line);
// buffer.append("\n");
}
mWebView.loadData(buffer.toString(), "text/html", "utf-8");

} catch (Exception e) {
Log.i("xxxx", "failed");
}

沒有留言: