Open Local Html File in Webview - Android
android, java
Solution
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;
}
}
try this
Problem
I have a saved a file in the root folder and am trying to open it in a webview. This is my code for saving: ``` 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..."); } ``` This is my code for recalling the file: ``` fileView.getSettings().setJavaScriptEnabled(true); fileView.loadUrl("file:///" + name); <--- ``` and inside the app it gives me a file not found error. Any insight is helpful.