Hi Everyone, I'm new to java and working on reading a text file into my java program. The issue with the code I have built is it only reads the text on each line and errors if there is more that one text on the line. Looking for some advice.
Here is the txt reader,
public boolean readInterestRates() { //start
boolean status = false;
try { //start
FileReader fis = new FileReader(new File("loanterms.txt"));
BufferedReader br = new BufferedReader(fis);
String line = null;
int i = 0;
while ((line = br.readLine()) != null) {
rates[i] = Double.parseDouble(line);
i++;
}
fis.close();
status = true;
} catch (Exception e) { //start
JOptionPane.showMessageDialog(this, "File Read Error!!!");
status = false;
} //end
I need it to read 1 2 3 4 5, and let me choose one of them, right now I can only get it to read
1
2
3
4
5
from the text file. I believe it has something to do with my rates[i] = Double.parseDouble(line); but can't figure out how to correct it.
Thanks.