如何从web中读取android中的文本文件? - 代码日志

如何从web中读取android中的文本文件?

我是Android的新手。我需要从Web上读取文本文件并显示该文本文件。有可能直接在android中查看文本文件。或者如何在android文本视图中阅读和显示文本文件?
使用DefaultHttpClient httpclient = new DefaultHttpClient();

HttpGet httppost = new HttpGet("http://www.urlOfThePageYouWantToRead.nl/text.txt");
HttpResponse response = httpclient.execute(httppost);
        HttpEntity ht = response.getEntity();

        BufferedHttpEntity buf = new BufferedHttpEntity(ht);

        InputStream is = buf.getContent();


        BufferedReader r = new BufferedReader(new InputStreamReader(is));

        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            total.append(line + "\n");
        }

        TextView.setText(total);

希望这可以帮助!

http://stackoverflow.com/questions/6099429/how-to-read-text-file-in-android-from-web

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:如何从web中读取android中的文本文件?