I have the following config file that I am trying to use to set global variables in my program
OUTPUT_FILE_PATH = filename2.txt
MAX_CRAWL_DEPTH = 2
NUMBER OF CRAWLERS = 10
SEED_URL = https://www.lehigh.edu/home
DOMAIN = lehigh.edu
DELAY = 10
To parse this text file I am using this
String line = "";
BufferedReader buffRead = new BufferedReader(new FileReader((CONFIG_FILE_PATH)));
Scanner charlie = new Scanner(line);
String varName;
while ((line = buffRead.readLine()) != null){
System.out.println(line);
charlie.useDelimiter(" = ");
varName = charlie.next();
System.out.println(varName);
if (varName == "OUTPUT_FILE_PATH")
OUTPUT_FILE_PATH = charlie.next();
else if (varName == "MAX_CRAWL_DEPTH")
MAX_CRAWL_DEPTH = charlie.nextInt();
else if (varName == "NUMBER_OF_CRAWLERS")
NUMBER_OF_CRAWLERS = charlie.nextInt();
else if (varName == "SEED_URL")
SEED_URL = charlie.next();
else if (varName == "DOMAIN")
DOMAIN = charlie.next();
else if (varName == "DELAY")
delay = charlie.nextInt();
}
I get this output when running the code
OUTPUT_FILE_PATH = filename2.txt
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1478)
at Globals.setGlobals(Globals.java:44)
Line 44 is where I set varName = charlie.next(); Any reason why this would be wrong? Any other tips on how to go about parsing this file? I feel like my if statements is not the best way to do it.