Results 1 to 2 of 2
Thread: Input Stream as an Object?
- 03-12-2011, 12:30 AM #1
Input Stream as an Object?
I am reading in a file using:
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.Java Code:JFileChooser fileopen = new JFileChooser(); String Title = "Please select your matrix file"; fileopen.setDialogTitle(Title); 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) { Lines++; } in.close(); //We have to account for the matrix dimensions row, so remove a row. RowCount = Lines - 1; } catch (Exception e) { System.out.println(e.toString()); System.exit(1); }
- 03-12-2011, 12:37 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
When you read the first time you can store in a collection such as arraylist or something.
Similar Threads
-
Http Input Stream read method
By chandan.mishra in forum Advanced JavaReplies: 2Last Post: 01-03-2011, 02:36 AM -
Object Input Stream EOFException
By FlyNn in forum New To JavaReplies: 1Last Post: 12-18-2010, 12:33 PM -
Input stream error
By Johnny68 in forum New To JavaReplies: 10Last Post: 08-05-2010, 06:20 PM -
Stream closed on a ClassLoader input
By RaistlinMajeren in forum Advanced JavaReplies: 15Last Post: 06-03-2010, 07:18 AM -
java.lang.NumberFormatException: For input stream:jav
By osval in forum New To JavaReplies: 2Last Post: 08-07-2007, 03:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks