English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am writing a program in Java. I need to read a file then store the data in an array. Since I need to declare the size of the array so I need to know how many records are in the file. Is there a quick way to find out the number of records in a file without reading through it? If I know the number of records then I can declare the array then read the file and store the data (meaning to read the file once).

2007-03-09 18:43:18 · 3 answers · asked by Sea_turtle 2 in Computers & Internet Programming & Design

3 answers

It depends on how the data stored in the file. If each record has its own line, then using the getLineNumber() method.

An alternative way is not to use Arrays and create an ArrayList object. You can declare a type-specific ArrayList by

ArrayList variable;

2007-03-09 19:58:22 · answer #1 · answered by Mick T 1 · 0 1

i think you shoult try reading the entire file, then call the getLineNumber() method..

2007-03-09 18:54:02 · answer #2 · answered by abd 5 · 0 0

you ask god.

2007-03-09 18:50:47 · answer #3 · answered by rocuronium77 2 · 0 1

fedest.com, questions and answers