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

前端 未结 7 567
孤街浪徒
孤街浪徒 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:10

    You can do something like this:

    File file = new File("Student.txt");
    
    try {
        Scanner scanner = new Scanner(file);
    
        //now read the file line by line...
        int lineNum = 0;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            lineNum++;
            if() { 
                System.out.println("ho hum, i found it on line " +lineNum);
            }
        }
    } catch(FileNotFoundException e) { 
        //handle this
    }
    

提交回复
热议问题