StringTokenizer to.. double Array[ ]

From: Dimitris (dimitris123_at_gmail.com)
Date: 03/27/05


Date: 27 Mar 2005 04:40:49 -0800

I am reading a .txt file, and trying to store each double number to an
array for further calculations.
I have problems adding the numbers to the array.
Here is what i am trying to do:
public void read(File afile) {

    FileInputStream fInpStr = null;
    BufferedReader bRead = null;
    StringTokenizer strTok = null;
    String line = null;
    String next = null;
    String[] jim;
    int i = 0;

    //temporary variables
    String variableName;
    double variableValue;

    //open the variable text file and catch any error.
    try {
      fInpStr = new FileInputStream(afile);
    }
    catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, "File not found " + afile,
                                    "Error",
JOptionPane.ERROR_MESSAGE);
      return;
    }
    variableName = "";
    variableValue = 0.0;

    try {

      bRead = new BufferedReader(new InputStreamReader(fInpStr));
      //first line
      variableName = bRead.readLine();
      while (strTok.hasMoreTokens()) {

      }
      // second line
      line = bRead.readLine();

      fInpStr.close();
    }
    catch (IOException e) {
      System.out.println(e.toString());
      JOptionPane.showMessageDialog(null, "Error reading file " +
afile,
                                    "Error",
JOptionPane.ERROR_MESSAGE);
    }

  } //end of read
_______________________________________

this is the code so far for reading the values. I think i have to add a
for loop to "loop" through the array, but i am cofused.



Relevant Pages

  • Newbie read image help
    ... reading one byte or one line per loop. ... array, that would be great if I could choose. ... is there any libraries out there that someone can ...
    (comp.lang.cpp)
  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Really Stuck, Please Help
    ... I am not sure how to construct an array. ... Reading Master Log", of the "Copreco Master Log" workbook. ... Dim sourceBook As String ...
    (microsoft.public.excel.programming)
  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)