- #1
TMM
- 92
- 0
So I made a program that finds files and searches in them for key terms using the scanner class in java.util.*;
I've written it something like this:
Scanner filereader = new Scanner(System.in);
String filename = filereader.nextLine();
Scanner searcher = new Scanner(new File(filename));
The problem is with the filename argument. I need quotes around it to fix the syntax, but even when my input contains quotes it doesn't quite work, and when I add them in the program itself they turn my variable, filename, into a string literal. Is there a way to get around this (some type of escape code perhaps?) or a different method altogether? Any help is much appreciated.
I've written it something like this:
Scanner filereader = new Scanner(System.in);
String filename = filereader.nextLine();
Scanner searcher = new Scanner(new File(filename));
The problem is with the filename argument. I need quotes around it to fix the syntax, but even when my input contains quotes it doesn't quite work, and when I add them in the program itself they turn my variable, filename, into a string literal. Is there a way to get around this (some type of escape code perhaps?) or a different method altogether? Any help is much appreciated.