No-eye-deer
No-eye-deer

Reputation: 51

Read remote text file in android

I am very new to android development so forgive my ignorance. I need to be able to read some text from a remote webpage at say 15 minute intervals. The webpage itself contains just one word with no html tags or formatting. If this is possible if someone could point me in the right direction I'd appreciate it.

Thanks

Upvotes: 5

Views: 5320

Answers (2)

Sven
Sven

Reputation: 41

You might want to put "in.close()" in a finally {} clause, to make sure it always closes

Upvotes: 4

aioobe
aioobe

Reputation: 420921

Sure, try the following

try {
    // Create a URL for the desired page
    URL url = new URL("yoursite.com/thefile.txt");

    // Read all the text returned by the server
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str = in.readLine();
    in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

Upvotes: 9

Related Questions