Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...