Read remote text file in android

I am very new to Android development, so forgive my ignorance. I need to read text from a remote web page, say, after 15 minutes. The web page itself contains only one word without html or formatting tags. If possible, if someone can point me in the right direction, I would appreciate it.

thank

+5
source share
2 answers

Of course, 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) {
}
+9
source

You might want to put "in.close ()" in the finally {} clause so that it always closes

+4
source

All Articles