[英]Read remote text file in android
我对android开发很新,所以请原谅我的无知。 我需要能够以15分钟的间隔从远程网页上读取一些文本。 网页本身只包含一个没有html标签或格式的单词。 如果有人可以指出我正确的方向,我会很感激。
谢谢
当然,请尝试以下方法
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) {
}
您可能希望将“in.close()”放在finally {}子句中,以确保它始终关闭
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.