java i/o... need help reading values from file

Discussion in 'Java' started by morc, Mar 2, 2006.

  1. morc

    morc Guest

    hey i need to read the values from some log files.

    the format is like this :

    Time Price
    082257 0.0295
    090110 0.03
    090200 0.03
    091503 0.0305
    091504 0.0305
    091514 0.0305
    091522 0.0305
    091917 0.0305
    092203 0.0305

    Does anybody have any suggestion of how id iterate through all these
    price values to find the highest and lowest??
    I will also be needing to find price values for certain times. but
    mainly my focus right now is just to retrieve the high and low. If
    anyone has any ideas how to go about his it would be greatly
    appreciated if you would post :)

    thanks alot
    -morc
     
    morc, Mar 2, 2006
    #1
    1. Advertising

  2. morc

    Guest

    , Mar 2, 2006
    #2
    1. Advertising

  3. morc

    Guest

  4. morc

    Roedy Green Guest

    On 2 Mar 2006 11:43:20 -0800, "morc" <> wrote,
    quoted or indirectly quoted someone who said :

    >092203 0.0305

    Since they are in fixed columns, you could use substring to extract
    them, or approximately extract them, then trim. Read the file with a
    BufferedReader
    http://mindprod.com/jgloss/string.html
    see http://mindprod.com/applets/fileio.html

    You could use a StringTokenizer trained to consider space as a
    discardable separator.
    http://mindprod.com/jgloss/stringtokenizer.html

    You could use a regex split on space.
    http://mindprod.com/jgloss/regex.html

    you could use a column-mode text editor to insert a comma down the
    middle and then read them as a CSV file.
    http://mindprod.com/jgloss/csv.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 3, 2006
    #4
  5. morc

    morc Guest

    hey thanks for those references. i tried using what visen gave me.
    Heres the code:

    DataInputStream in = new DataInputStream(new
    FileInputStream("C:/marc_repository/USXPdata.txt"));
    char ch = in.readChar();
    System.out.println(ch);

    i began to do that just to test it but for some reason. The only values
    i get are "?".
    I treid the deprecated readLine and it read the first line showing that
    i was connected tot he file.
    Does anybody know how come its reading question marks??
    and also does anyone know of a way to skip the first line?

    Thanks again for the help.
    -morc
     
    morc, Mar 3, 2006
    #5
  6. morc

    Roedy Green Guest

    On 3 Mar 2006 09:30:18 -0800, "morc" <> wrote,
    quoted or indirectly quoted someone who said :

    >i began to do that just to test it but for some reason. The only values
    >i get are "?".

    readChar is expecting 16-bit chars. If your stream is encoded 8-bit
    bytes you need to use an InputStreamReader.

    Dump the first 16 bytes of the file in hex and tell me what you think
    it means and I can be more specific about the classes you need to read
    it.

    http://mindprod.com/applets/fileio.html
    http://mindprod.com/jgloss/hex.html

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. srikanth
    Replies:
    1
    Views:
    289
    Mike Wahler
    Jun 28, 2005
  2. bahoo
    Replies:
    8
    Views:
    389
    Bruno Desthuilliers
    Apr 4, 2007
  3. Tom

    Need help reading file data

    Tom, Sep 30, 2007, in forum: C Programming
    Replies:
    4
    Views:
    409
  4. Amkcoder

    Need help reading a file.

    Amkcoder, Oct 4, 2008, in forum: C Programming
    Replies:
    6
    Views:
    329
    CBFalconer
    Oct 5, 2008
  5. Replies:
    5
    Views:
    110
    Chris Angelico
    May 14, 2014
Loading...

Share This Page