I would like to find out how to print a a certain string from an input file using a scanner. For the string to be printed the line must start with *star and the string must be surrounded by quotation marks, and be the next token and on the same line as *star ignoring white space of course.
Sample input text file: "test.txt"
this is a test
*star "variableX"
more testing
*star "variableY
much more
testing
*star next"variableZ"
Based on this sample input text the output should be only.
"variableX"
Here is part of my code:
Scanner scanner = new Scanner (new File ("test.txt"));
while (scanner.hasNextLine()){
if(scanner.hasNext("*star")) {
scanner.next();
if(scanner.hasNext()){
String test = scanner.next();
System.out.println(test);
}
But it's missing some key things. Help is much appreciated!