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
           }

1 Answer 1

1

Use equals instead of ==.

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

== checks if two references point to the same object, which won't be true in that case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.