I know I need to use the input.useDelimeter
method, but for some reason when I try to make the two delimiters a forward slash and the newline like so, input.useDelimiter("[/\n]");
it gives me a input mismatch error. i have also tried it like ("/\n"); and ("[/\\n]");
here is the method in question.
public static void main(String[] args)
throws FileNotFoundException {
int month = 0;
int day = 0;
int year = 0;
File file = new File("dates.txt");
Scanner input = new Scanner(file);
if (file.exists()){
while (input.hasNextLine()){
input.useDelimiter("[/]");
month = input.nextInt();
day = input.nextInt();
year = input.nextInt();
System.out.print(day + "-" + month + "-" + year + "\n");
}
}
}
when I use a text file that doesn't include newlines, and only forward slashes it works just fine, but for some reason I can't get it to recognize the newline character as a delimiter.