Read text file and search string in android

I am my Android application, I would like to read a text file that is located on the SD card. Read the file to search for the string: "some string" and want to get the value for this string. Is there any way I can do this in android.

Share your valuable suggestions.

+5
source share
1 answer

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();
    }
+3
source

All Articles