Method to find string inside of the text file. Then getting the following lines up to a certain limit

前端 未结 7 566
孤街浪徒
孤街浪徒 2020-12-08 15:35

So this is what I have so far :

public String[] findStudentInfo(String studentNumber) {
                Student student = new Student();
                Scan         


        
7条回答
  •  温柔的废话
    2020-12-08 16:11

    Here is a java 8 method to find a string in a text file:

    for (String toFindUrl : urlsToTest) {
            streamService(toFindUrl);
        }
    
    private void streamService(String item) {
            try (Stream stream = Files.lines(Paths.get(fileName))) {
               stream.filter(lines -> lines.contains(item))
                           .forEach(System.out::println);
    
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题