I am trying to read a file and extract all the tokens but im having a hard time programming it correctly
heres the file:
Jane Rivers, A-902, 05/16/2001, 1, 16.25
Bob Cox, S-823, 06/21/1990, 2, 17.50
Ann Ramsey, A-715, 02/12/1998, 1, 16.25
Joseph Chandler, P-723, 12/22/2000, 3, 14.35
Arnold Kennedy, S-133, 08/10/1999, 2, 18.20
Larry Huber, P-198, 02/12/2000, 3, 17.25
Annette Wilson, H-501, 04/04/1995, 1, 20.25
Robert Ferguson, H-674, 04/10/2002, 2, 16.50
Ava Gaines, H-434, 01/05/2000, 3, 15.65
and heres my code
import java.io.*; import java.util.StringTokenizer; import java.util.Scanner; public class EmployeeDemo { public static void main(String[] args) throws IOException { String line, fileIn = "Information.txt", fileOut = "Department.txt"; StringTokenizer tokens; String name; String number; int hire; int shift; double pay; File fr = new File (fileIn); Scanner inFile = new Scanner (fr); PrintWriter outFile = new PrintWriter (fileOut); line = inFile.nextLine(); while (inFile.hasNext()) { tokens = new StringTokenizer(line, ",-/"); name = null; number = null; hire = 0; shift = 0; pay = 0.0; if (tokens.hasMoreTokens()) name = tokens.nextToken(); if (tokens.hasMoreTokens()) number = tokens.nextToken(); if (tokens.hasMoreTokens()) hire = Integer.parseInt(tokens.nextToken()); if (tokens.hasMoreTokens()) shift = Integer.parseInt(tokens.nextToken()); if (tokens.hasMoreTokens()) pay = Double.parseDouble(tokens.nextToken()); System.out.println(name + number + hire + shift + pay); line = inFile.nextLine(); } inFile.close(); outFile.close(); } }