我有这个代码,它可以在文本文件中找到文本并将其放在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
}
答案 0 :(得分:1)
使用equals
代替==
。
if(total.toString().equals("Text"))
==
检查两个引用是否指向同一个对象,在这种情况下不会为真。