Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read remote text file in android

Tags:

java

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

like image 566
No-eye-deer Avatar asked Nov 18 '10 15:11

No-eye-deer


2 Answers

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) {
}
like image 97
aioobe Avatar answered Nov 18 '22 07:11

aioobe


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

like image 44
Sven Avatar answered Nov 18 '22 09:11

Sven