确定文件是否包含android中的字符串

时间:2013-01-27 04:05:15

标签: android string file

正如标题所说,我正在寻找一个简短的函数,如果有特定的字符串,则读取文件,并且//如果存在则执行某些操作。例如,如果在test.txt文件中存在字符串TestString。 有人会建议我采用一种方法吗?

1 个答案:

答案 0 :(得分:1)

  InputStream is = //--open an input stream from file--
  BufferedReader rd = new BufferedReader(new InputStreamReader(is,"UTF-8"));
  String line;

  while ( (line = rd.readLine()) != null ){
      if(line.matches(".*TestString.*")){ //--regex of what to search--
          //--do something---
          break; //--if not want to search further--
      }
  }
相关问题