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 ?
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.
A Text file in Android can be used for accessing or reading the information or text present in it.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With