Creating a Java Program to Search a File for a Specific Word

后端 未结 3 918
长发绾君心
长发绾君心 2021-01-01 07:16

I am just learning that language and was wondering what a more experience Java programmer would do in the following situation?

I would like to create a java program

3条回答
  •  渐次进展
    2021-01-01 07:53

    Unless the file is very large, I would

    String text = IOUtils.toString(new FileReader(filename));
    boolean foundWord = text.matches("\\b" + word+ "\\b");
    

    To find all the text between your word you can use split() and use the length of the strings to determine the position.

提交回复
热议问题