I have used a BufferedReader to read in information from a txt file. I know the file is reading but I cannot select the first index (bookID number) to go through my if statement. I want the first line of the string to match with the bookID and then complete the if statements without skipping to the book is not found statement. Code below.
String bookID = jTextField7.getText();
String quantity = jTextField8.getText();
jLabel9.setText("Item #" + Integer.toString(currItem) + "info");
jButton8.setEnabled(false);
jButton9.setEnabled(true);
BufferedReader br = null;
String sCurrentLine;
try {
//String sCurrentLine;
br = new BufferedReader(new FileReader("inventory.txt"));
while ((sCurrentLine = br.readLine()) != null) {
String[] split = sCurrentLine.split(",");
System.out.println(sCurrentLine);
if (split[0] == bookID) {
int discount = calculateDiscount(Integer.parseInt(quantity));
double itemSubTotal = (Integer.parseInt(quantity)*new BigDecimal(split[2]).doubleValue()*(discount/100));
subTotal += itemSubTotal;
String info = split[0] + " " + split[1] + " " + split[2] + " " + quantity + " " + Integer.toString(discount) + " " + (Integer.parseInt(quantity)*new BigDecimal(split[2]).doubleValue()*(discount/100));
books.add(info);
jTextField9.setText(info);
return;
}
}
}
catch (IOException e ){
e.printStackTrace();
}
finally {
try {
if (br != null)br.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
JOptionPane.showMessageDialog(null, "Book ID " + bookID + " not in File");
}
I would appreciate any help. Thank you.