Android WebView加载本地Html文件

WebView wView = (WebView)findViewById(R.id.wv1);     
        WebSettings wSet = wView.getSettings();
        wSet.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        wSet.setJavaScriptEnabled(true);
        InputStream is = getResources().openRawResource(R.raw.index);
        InputStreamReader isr = null;
		try {
			isr = new InputStreamReader(is,"GBK");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        BufferedReader br = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer();
        String str = "";
        
        try {
			while((str = br.readLine()) != null){
				sb.append(str);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        String html = sb.toString();
        wView.loadDataWithBaseURL(null,html, "text/html",  "utf-8", null);

你可能感兴趣的:(android)