364,083 Members | 5932 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Populate Array of type Double from text file

bmbuke
P: 2
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
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. try{
  3.     FileInputStream fstream = new FileInputStream("InterestFromFile.txt");
  4.     DataInputStream in = new DataInputStream(fstream);
  5.     BufferedReader br = new BufferedReader(new InputStreamReader(in));
  6.     String strLine;
  7.         while ((strLine = br.readLine()) != null)   {
  8.                System.out.println (strLine);
  9.          }
  10.      in.close();
  11.      }catch (Exception e){//Catch exception if any
  12.      System.err.println("Error: " + e.getMessage());
  13.      }
  14.  
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!
Jan 19 '12 #1
Share this Question
Share on Google+
1 Reply


bmbuke
P: 2
Anyone have any ideas? I could really use some help.
Jan 20 '12 #2

Post your reply

Help answer this question



Didn't find the answer to your Java question?

You can also browse similar questions: Java array java