我在根文件夹中保存了一个文件,并尝试在Webview中打开它.
这是我的保存代码
OutputStream outstream = null; outstream = openFileOutput(fileName,MODE_WORLD_READABLE); /// if file the available for writing if (outstream != null) { /// prepare the file for writing OutputStreamWriter outputreader = new OutputStreamWriter(outstream); BufferedWriter buffwriter = new BufferedWriter(outputreader); /// write the result into the file buffwriter.write(result); } /// close the file outstream.close(); } catch (java.io.FileNotFoundException e) { System.out.println("File not found in the writing..."); } catch (IOException e) { System.out.println("In the writing..."); }
fileView.getSettings().setJavaScriptEnabled(true); fileView.loadUrl("file:///" + name); <---
任何见解都是有帮助的.
解决方法
WebView mWebView=(WebView)findViewById(R.id.mWebView); mWebView.loadUrl("file:///book.html"); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setSaveFormData(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.setWebViewClient(new MyWebViewClient()); private class MyWebViewClient extends WebViewClient { @Override //show the web page in webview but not in web browser public boolean shouldOverrideUrlLoading(WebView view,String url) { view.loadUrl (url); return true; } }
尝试这个