read a text file and search a string in android

后端 未结 1 1323
一整个雨季
一整个雨季 2021-01-13 09:38

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 valu

相关标签:
1条回答
  • 2021-01-13 10:20

    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();
        }
    
    0 讨论(0)
提交回复
热议问题