【问题标题】:determine if a file contains a string in android确定文件是否包含android中的字符串
【发布时间】:2013-01-27 04:05:14
【问题描述】:

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

【问题讨论】:

    标签: android string file


    【解决方案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--
          }
      }
    

    【讨论】:

      猜你喜欢
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2019-06-11
      • 2020-12-28
      相关资源
      最近更新 更多