2010-04-09 48 views
1

我目前的代碼需要從網上讀取外來字符,目前我的解決方案工作,但它非常慢,因爲它使用InputStreamReader讀char字符。無論如何要加快速度並完成工作?java:加速讀取外來字符

// Pull content stream from response 
     HttpEntity entity = response.getEntity(); 
     InputStream inputStream = entity.getContent(); 

     StringBuilder contents = new StringBuilder(); 
     int ch; 
     InputStreamReader isr = new InputStreamReader(inputStream, "gb2312"); 
      // FileInputStream file = new InputStream(is); 
     while((ch = isr.read()) != -1) 
      contents.append((char)ch); 
     String encode = isr.getEncoding(); 

     return contents.toString(); 

回答

6

BufferedReader

包裝你的InputStreamReader爲 字符,數組和行的高效讀取。

InputStreamReader isr = new InputStreamReader(inputStream, "gb2312"); 
Reader reader = new BufferedReader(isr);