tags:

views:

69

answers:

1

I my android application,i would like to read a text file which is placed on the sdcard. Read the file to search for a string: "some string" and would like to get the value for that string. Is there any way that i can do that in android.

Please share your valuable suggestions.

+1  A: 

File file = new File(your file);

    try {
        FileInputStream in = new FileInputStream(file);
                    int len = 0;
                    byte[] data1 = new byte[1024];
            while ( -1 != (len = in.read(data1)) ){

                                 if(new String(data1, 0, len).contains(Your String))
                                     //do something...
                     }


    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Umesh
Thanks Umesh.Its working fine.Do you have any idea like how i can get the text next to it.
Remmyabhavan
store the data coming from the web in a string then use indexOf property and find out the index of your string.startIndex = index_of_your_string + yourString.length(), then use substring and retrieve the next string.
Umesh