2013-05-21 56 views
1

無法讀取保存(馬來亞)字符串內容代碼下載非英語HTML文件中的WebView

String A = "<html><head><style>" 
      + "@font-face { font-family: Manorama;src: url(file:///android_asset/Manorama.ttf); }" 
      + "h1 { color: #222;font-size: 26px;margin-top: 32px; }" 
      + "</style></head><body><h1>" 
      + "<font face=\"Manorama\">ØíxàW ¥çÄÞùßxßÏßW 190 æd¿ÏßÈß</font><!--3546062932-->" 
      + "</p><body></html>"; 

    FileOutputStream OStream = null; 
    try { 
     OStream = openFileOutput("0.html", Context.MODE_PRIVATE); 
     OStream.write(A.getBytes("UTF-32")); 
     OStream.close(); 
    } catch (Exception e) { 
    } 

,它正在完美

但是,當我從服務器下載後執行相同的操作不工作(字符是在網頁視圖)非可讀,

查找下面的代碼,

 HttpClient client = new DefaultHttpClient(); 
     HttpResponse response = null; 
     InputStream in = null; 
     try { 
      response = client.execute(new HttpGet(
        "http://tinymail.in/mail_pipe/thozhilveedhi/pull")); 
      in = response.getEntity().getContent(); 
     } catch (Exception e) { 
     } 
     BufferedReader reader = new BufferedReader(
       new InputStreamReader(in)); 
     StringBuilder string = new StringBuilder(); 
     String line = null; 
     try { 
      while ((line = reader.readLine()) != null) { 
       string.append(line); 
      } 
      in.close(); 
     } catch (Exception e) { 
     } 

     String[] A = (string.toString()).split("__"); 

     for (int i = 0; i < A.length; i++) { 
      if (A[i] != "") { 

       try { 
        FileOutputStream OStream = openFileOutput(i + ".html", 
          Context.MODE_PRIVATE); 
        OStream.write(A[i].getBytes("UTF-32")); 
        OStream.close(); 
       } catch (Exception e) { 
       } 

      } 
     } 

我認爲問題是在數據傳送從服務器到Android,我能做什麼?
Base 64傳輸編碼是否解決了這個問題?
請幫助

回答

0
 HttpClient client = new DefaultHttpClient(); 
     HttpResponse response = null; 

     try { 
      response = client.execute(new HttpGet(
        "http://tinymail.in/mail_pipe/thozhilveedhi/pull")); 
     } catch (Exception e) { 
     } 

     HttpEntity entity = response.getEntity(); 
     if (entity != null) { 

      String data = EntityUtils.toString(entity); 
      String[] A = null; 

..
讀取文件&下面的代碼來保存

    try { 
         FileOutputStream OStream = openFileOutput(i 
           + ".html", Context.MODE_PRIVATE); 
         OStream.write(A[i].getBytes("UTF-16")); 
         OStream.close(); 
        } catch (Exception e) { 
        } 

       } 
      } 

     } 
+0

OStream.write(A [i]於.getBytes( 「ISO-8859-1」)); –