• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to display a text file

can someone point me in the right direction. not sure even what to search for. trying to display a text file in app. anything would help right now.
 
I don't have the file anywhere yet because I don't know where to start or what methods to use.. I want to click on a listactivity and display the file. maybe I should be puttinig in a DB not sure. file is about 2megs. I have it in pdf also. either would work.
 
Code:
public String readFile(BufferedReader br)
{
    StringBuilder sb = new StringBuilder();
    String tmp;

    try
    {
         while((tmp = br.readLine()) != null)
             sb.append(tmp).append("\n");
     }
    catch(IOException e)
    {
          Toast.makeText("Failed to read file").show();
          return null;
    }

    return sb.toString();
}

This returns a string containing the text file. All you need to do is set the textview's text to the returned string and you should be good to go.
 
Back
Top Bottom