I`m trying to write java program that take license number from one file and put it in another file. This what I wrote until now:
import java.io.File;
import java.util.Formatter;
import java.util.Scanner;
public class license {
public static void main(String[] args) {
openFile();
readFileAndConvert();
}
private static Scanner x;
// Open original license file
public static void openFile() {
try {
x = new Scanner(new File("C:\\Users\\me\\Desktop\\originalLicense.txt"));
} catch (Exception e) {
System.out.println("Error");
}
}
public static void readFileAndConvert() {
String licenseNum;
Formatter newLicense = null;
while (x.hasNext()) {
licenseNum = x.next();
if (licenseNum == "123") {
try {
newLicense = new Formatter("C:\\Users\\me\\Desktop\\newLicense.txt");
} catch (Exception e) {
System.out.println("Error");
}
newLicense.format("%", licenseNum);
}
}
}
}
I used youtube videos to write this and now I can`t find the problem, Is anybody can guess what can be the problem?