2012-02-23 168 views
0

我有一个存储在“res \ raw”文件夹中的“.HTML”文件。 我用下面的代码,以显示我的文件的内容:网页不显示特殊字符

static String TAG="WebPageShowActivity"; 
    WebView mWebView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.webpagedisplay); 
     String summary = readRawTextFile(this,R.raw.spotlighterhelp); 
       //getResources().openRawResource(R.raw.spotlighterhelp).toString(); 
     mWebView = (WebView) findViewById(R.id.webview); 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.loadDataWithBaseURL (null,summary, "text/html","ASCII" ,null); 
    } 
    public static String readRawTextFile(Context ctx, int resId) 
    { 
      InputStream inputStream = ctx.getResources().openRawResource(resId); 

      InputStreamReader inputreader = new InputStreamReader(inputStream); 
      BufferedReader buffreader = new BufferedReader(inputreader); 
      String line; 
      StringBuilder text = new StringBuilder(); 

      try { 
      while ((line = buffreader.readLine()) != null) { 
       text.append(line); 
       } 
      } catch (IOException e) { 
       return null; 
      } 
      Log.e(TAG, "file content: "+text.toString()); 
      return text.toString(); 
    } 

现在,我的问题是:无论是编码类型,它不显示特殊字符,如“或者”我该怎么做,使这些字符显示呢?

以下是输出我得到 enter image description here

+0

问题已解决。我已将.doc文件转换为.html,因此我已将“”转换为一些特殊字符“”。现在替换他们工作正常 – Pallavi 2012-02-23 07:26:16

回答

0

我觉得可能工作,尝试使用UTF-8,而不是ASCII为网页视图。

mWebView.loadDataWithBaseURL (null,summary, "text/html","UTF-8" ,null);