public static String priceReader(String clotheOrder) {
String price = "";
try {
File file = new File("src\\application\\clotheprice.txt");
Scanner scan = new Scanner(file);
while (scan.hasNext()) {
String clotheCode = scan.next();
String clothePrice = scan.next();
String clotheStocks = scan.next();
if (clotheOrder == clotheCode) {
price = clothePrice;
}
}
scan.close();
}
catch (FileNotFoundException e) {
System.out.println("Error occured.");
e.printStackTrace();
}
return price;
}
Above is the java method that I'm trying to run. If this method is not functional, is there other way to read a file then return a string from the file? Thank you in advance.