Open HTML file from assets folder

后端 未结 5 1731
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 02:21

I am trying to open local html file in my Android application.

The file is located under my assets folder. So I am setting a WebViewClient and loading my page into i

5条回答
  •  灰色年华
    2021-01-20 02:56

    I think, It'd better use "raw" folder. That code works properly.

     InputStream is = getResources().openRawResource(R.raw.html_file);
    
         try {
             int size = is.available();
             byte[] buffer = new byte[size];
             is.read(buffer);
             is.close();
             String str = new String(buffer);
             }catch (IOException e){
                e.printStackTrace();
             }
             webView.loadDataWithBaseURL("", str, "text/html", "UTF-8", "");
    

提交回复
热议问题