如何从Android的网络阅读的文本文件? [英] How to read text file in android from web?

查看:132
本文介绍了如何从Android的网络阅读的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来android.I需要读取网页的文本文件,并显示该文本file.Is有没有可能直接在安卓查看的文本文件。要不怎么读取和Android的TextView中显示的文本文件?

I am new to android.I need to read text file from Web and display that text file.Is there any possibility to view a text file directly in android. or else how to read and display the text file in android textview ?

推荐答案

使用了 DefaultHttpClient的HttpClient =新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);

希望这有助于!

Hope this helps!

这篇关于如何从Android的网络阅读的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆