2013-08-04 58 views
0

我有這個代碼在獲取文本文件中找到的文本,並將其放在一個TextView中。從網站閱讀文本,並把它放在一個字符串(安卓,Eclipse)

DefaultHttpClient httpclient = new DefaultHttpClient(); 
    HttpGet httppost = new HttpGet("http://www.website.nl/text.txt"); 
    HttpResponse response = httpclient.execute(httppost); 
    HttpEntity ht = response.getEntity(); 

    BufferedHttpEntity buf = new BufferedHttpEntity(ht); 

    InputStream is = buf.getContent(); 


    BufferedReader r = new BufferedReader(new InputStreamReader(is)); 

    StringBuilder total = new StringBuilder(); 
    String line; 
    while ((line = r.readLine()) != null) { 
     total.append(line + "\n"); 
    } 

我試過了。我如何使用「總計」作爲字符串?

if(total.toString() == "Text") 
      { 
       //TODO 
      } 

回答

1

使用equals而不是==。如果

if(total.toString().equals("Text")) 

==檢查兩個引用指向同一個對象,該對象也不會在這種情況下,真實的。

相關問題