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

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

问题描述

我是 android 新手.我需要从 Web 读取文本文件并显示该文本文件.是否有可能直接在 android 中查看文本文件.或者如何在 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 = 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 + "
");
        }

        TextView.setText(total);

希望这会有所帮助!

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

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