从网站读取文本并将其放在一个字符串中(Android,Eclipse)

时间:2013-08-04 18:59:55

标签: android eclipse web

我有这个代码,它可以在文本文件中找到文本并将其放在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");
    }

我试过这个。我如何使用“total”作为字符串?

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

1 个答案:

答案 0 :(得分:1)

使用equals代替==

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

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