Results 1 to 2 of 2
  1. #1
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Rep Power

    Default Input Stream as an Object?

    I am reading in a file using:

    Java Code:
      JFileChooser fileopen = new JFileChooser();
            String Title = "Please select your matrix file";
            int ret = fileopen.showDialog(null, "Open file");
            if (ret == JFileChooser.APPROVE_OPTION) {
                file = fileopen.getSelectedFile();
            try {
                FileInputStream fstream = new FileInputStream(file);
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String str;
    //Iterate over each line in the file and get a count on the number of Rows. This will help determine the
    //size of the LinkedListArray.
                while ((str = in.readLine()) != null) {
    //We have to account for the matrix dimensions row, so remove a row.
                RowCount = Lines - 1;
            } catch (Exception e) {
    This is to get the number of rows in the file so I can initialize a LinkedListArray to its proper size. Later in my program, I create a new file input stream and read in lines from the same file again to actually do the processing. Is there a way that I can gather thee data from the file during the first process, and store it, so that the 2nd time I dont have to read the file again.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

Similar Threads

  1. Http Input Stream read method
    By chandan.mishra in forum Advanced Java
    Replies: 2
    Last Post: 01-03-2011, 02:36 AM
  2. Object Input Stream EOFException
    By FlyNn in forum New To Java
    Replies: 1
    Last Post: 12-18-2010, 12:33 PM
  3. Input stream error
    By Johnny68 in forum New To Java
    Replies: 10
    Last Post: 08-05-2010, 06:20 PM
  4. Stream closed on a ClassLoader input
    By RaistlinMajeren in forum Advanced Java
    Replies: 15
    Last Post: 06-03-2010, 07:18 AM
  5. Replies: 2
    Last Post: 08-07-2007, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts