Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read text file in android from web?

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 ?

like image 907
Krishna Avatar asked May 23 '11 15:05

Krishna


People also ask

How to read text file from URL in Android example?

just put it inside a new thread and start the thread it will work. new Thread(new Runnable() { @Override public void run() { try { URL url = new URL("URL");//my app link change it HttpsURLConnection uc = (HttpsURLConnection) url. openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.

What is text file Android?

A Text file in Android can be used for accessing or reading the information or text present in it.


1 Answers

Use the 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);

Hope this helps!

like image 196
BadSkillz Avatar answered Oct 11 '22 07:10

BadSkillz