0

I have this code which works in getting the text found in text file and putting it in a TextView.

    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");
    }

I have tried this. How can i use "total" as string ?

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

1 回答 1

1

使用equals而不是==.

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

==检查两个引用是否指向同一个对象,在这种情况下不是这样。

于 2013-08-04T19:04:48.760 回答