Here is an example of how to do this. If the file is so large that it takes more than 5 seconds to read, then most likely it will be AsyncTask .
// first open the file and read it into a StringBuilder String cardPath = Environment.getExternalStorageDirectory(); BufferedReader r = new BufferedReader(new FileReader(cardPath + "/filename.txt")); StringBuilder total = new StringBuilder(); String line; while((line = r.readLine()) != null) { total.append(line); } r.close(); // then get the TextView and set its text TextView txtView = (TextView)findViewById(R.id.txt_view_id); txtView.setText(total.toString());
EDIT
You can only change user interface elements in the user interface stream. The topic documentation contains more detailed information. When you try to do this from another thread, you get this (from your pastebin):
E/AndroidRuntime( 8517): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
I think the easiest solution uses AsyncTask , as I recommended earlier. You just put your working code in one function ( doInBackground() ), and your user interface code in another ( onPostExecute() ) and AsyncTask make sure that they are called in the correct threads and in order. The documentation I'm attached to has examples of loading bitmaps, which is roughly the same as loading text.
source share