1

Possible Duplicate:
How to read text file in Android?

I am developing a web app where I am getting response from the web in form of response. I am saving that response successfully in the file. I want to read that response from the file and use it as a textview field. Please help me for the same .

App has been activated successfully. Id is****289****.Ref 1 Reference 1.Ref 2 is Reference 2

Fields in bold is what I am getting as response.Please help me for the same

Community
  • 1
  • 1
onkar
  • 85
  • 10

2 Answers2

1

In what format is the response you are receiving from the server?
If it is XML or JSON you could use a XML or JSON parser and select the fields you need.

If neither of both, but you control the server, you can modify your response output to be in XML or JSON.

At last, if you don't control the server, then most probably you'll need to make use of regex in order to get correctly your values for every request.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
1

You can read line by line and set lines in text view:

    File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard,"file.txt");
    if (file.exists()) 
    {
        ArrayList<String> readed = new ArrayList<String>();

        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;

            while ((line = br.readLine()) != null) {
                readed.add(line);

            }
        }
        catch (IOException e) {

        }
        txtview1.setText(readed.get(i));
        txtview2.setText(readed.get(i+1));
        txtview3.setText(readed.get(i+2));

    }
DanM
  • 1,530
  • 4
  • 23
  • 44