Hi everyone. This is my first time posting to this forum and I am only about 9 weeks into java programming so I am still learining a lot!
My primary issue is I need to know how to fill an array of type double with values read from a text file.
Update 1.20.12 - So I have made some good progress and now here is what I need help with. In my variable declarations at the beginning of my file I have declared this double array
- double[] interest = {5.35, 5.5, 5.75};
When I get this working properly I know that I will be needing to remove the values from this array so that the text file can populate them, but for testing purposes they are in there.
Next, I have successfully been able to read my text file and to output that to the console window using the following:
-
-
try{
-
FileInputStream fstream = new FileInputStream("InterestFromFile.txt");
-
DataInputStream in = new DataInputStream(fstream);
-
BufferedReader br = new BufferedReader(new InputStreamReader(in));
-
String strLine;
-
while ((strLine = br.readLine()) != null) {
-
System.out.println (strLine);
-
}
-
in.close();
-
}catch (Exception e){//Catch exception if any
-
System.err.println("Error: " + e.getMessage());
-
}
-
So what I am guessing is that instead of using System.out.println (strLine) to print the contents of the text file to the console window, I will need to change that line to somehow fill the interest[] array that I have already declared earlier, but I don't know how to do that.
Again, thanks ahead of time for your help!