读取文本文件从Android上服务器 [英] Reading Text File From Server on Android
本文介绍了读取文本文件从Android上服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的服务器上的一个文本文件中。我想从我的Android应用程序打开的文本文件,然后显示在一个TextView的文本。我无法找到如何做一个服务器的基本连接的任何实例和饲料将数据转换成字符串。
I have a text file on my server. I want to open the text file from my Android App and then display the text in a TextView. I cannot find any examples of how to do a basic connection to a server and feed the data into a String.
任何帮助,您可以提供将AP preciated。
Any help you can provide would be appreciated.
推荐答案
请尝试以下操作:
try {
// Create a URL for the desired page
URL url = new URL("mysite.com/thefile.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
(从 Exampledepot采取:从网址获取文本)
如果在Android上正常工作。
Should work well on Android.
这篇关于读取文本文件从Android上服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文