I have the following code to read a line from a file and if it is equal to "true"
, set a boolean value to true
, and if not, set the boolean to false
:
BufferedReader reader = new BufferedReader(new FileReader(optionsFile));
stringFromFile = reader.readLine();
System.out.println("SFX plain text: " + stringFromFile);
if (stringFromFile == "true") {
SFX = true;
}
else {
SFX = false;
}
System.out.println("SFX: " + SFX);
However, when executed, the following comes up in the log (I have excluded the package name because it has personal details on it):
04-09 23:35:39.980 9686-9686/<PACKAGE NAME> I/System.out: SFX plain text: true
04-09 23:35:39.980 9686-9686/<PACKAGE NAME> I/System.out: SFX: false
Obviously, the if statement is evaluating the string incorrectly, but I've tried many things, and I've been unable to fix it. Does anyone know what's wrong, or how to fix it? Any help would be much appreciated.
P.S: If it's relevant, the text file is written with the following code:
writer = new BufferedWriter(new FileWriter(optionsFile));
if (SFX) {
writer.write("true");
System.out.println("SFX: true");
}
else {
writer.write("false");
System.out.println("SFX: false");
}
writer.newLine();
writer.close();