I have a program where a user enters a name and a gender, then the program is suppose to read through all these yob####.txt files to see if it contains that name,gender. if it does, i need to be able to get the number from it. in the yob####.txt files every single line is formatted like this "Mary,F,30045" the number is the number of times that name has been given to a baby for that year. I dont know how to get the number, i think i know how to find if it contains the Mary,F part but how do i get that number? heres my code:
package mat2670; import java.util.*; import java.io.*; public class BabyNames { public static void main(String[] args) throws FileNotFoundException { //Set up the scanner to get a file Scanner console = new Scanner(System.in); System.out.print("Please enter a name: "); String name = console.nextLine(); System.out.print("Please enter a gender (M or F): "); String gender = console.nextLine(); String genName = name + "," + gender; // Directory path here String path = "C:\\Users\\Connor Moore\\Documents\\yobdata"; String files; File folder = new File(path); File[] Files = folder.listFiles(); //loop to go through each file in the directory i have them in for (int i = 0; i < Files.length; i++) { Scanner nextFile = new Scanner(Files[i]); if (Files[i].isFile()) { while (nextFile.hasNextLine()) { String nextLine = nextFile.nextLine(); if(nextLine.contains(genName)) { //this is where im stuck, im not too sure how to get the number. from the string that contains the number i need. } } } } } }