2010-08-16 47 views
1

我想問一下,我們可以在android中轉換輸入源類型數據。我的概率是在這裏,我從URL中獲取數據不是以標籤形式。我在輸入源類型中獲取輸出。之後,我想解析數據的意思是這種可能嗎?將輸入源轉換爲android中的意思數據

如果這可能,那我該如何實現?

plz help

回答

3

我沒有正確理解你的問題。但如果你想將你的輸入流轉換成字符串,你可以做這樣的事情

public String convertStreamToString(InputStream is) throws IOException { 
     /* 
     * To convert the InputStream to String we use the BufferedReader.readLine() 
     * method. We iterate until the BufferedReader return null which means 
     * there's no more data to read. Each line will appended to a StringBuilder 
     * and returned as String. 
     */ 
     if (is != null) { 
      StringBuilder sb = new StringBuilder(); 
      String line; 

      try { 
       BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); 
       while ((line = reader.readLine()) != null) { 
        sb.append(line).append("\n"); 
       } 
      } finally { 
       is.close(); 
      } 
      return sb.toString(); 
     } else {   
      return ""; 
     } 
    } 
+0

非常感謝,它會真的幫助我。 – 2010-08-16 10:46:49