SamJ
SamJ

Reputation: 423

Read Text from website and put it in a string (Android , Eclipse)

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
           }

Upvotes: 0

Views: 570

Answers (1)

MaciejGórski
MaciejGórski

Reputation: 22232

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.

Upvotes: 1

Related Questions