Reading array of unknown size from file to array

D

Denis Palas

Dear All

My program needs to read contents of a file into an array , for example my
file contains :


4 3 4
2 3 1 5
1 2
2 4 5 6 7 7

I deeply appreciate your help with this question :

How can I set up an array , specially that my column sizes are different as
you can see , to fill it with contents of a file?


Thank You
Denis
 
B

bugbear

Denis said:
Dear All

My program needs to read contents of a file into an array , for example my
file contains :


4 3 4
2 3 1 5
1 2
2 4 5 6 7 7

I deeply appreciate your help with this question :

How can I set up an array , specially that my column sizes are different as
you can see , to fill it with contents of a file?

You either need 2 passes, or a more dynamic data structure
than an array.

The "obvious" answer is an ArrayList or ArrayLists.

BugBear
 
D

Daniel Pitts

Denis said:
Dear All

My program needs to read contents of a file into an array , for example my
file contains :


4 3 4
2 3 1 5
1 2
2 4 5 6 7 7

I deeply appreciate your help with this question :

How can I set up an array , specially that my column sizes are different as
you can see , to fill it with contents of a file?


Thank You
Denis
You would be better off if you also told us what you expected the array
to look like.

{4,3,4}
{2,3,1,5}
{1, 2}
{2, 4, 5, 6, 7, 7}

If thats the case, then you need to read the file one line at a time,
and then build the array based on the number of tokens. Or use an
ArrayList (which automatically resizes for you).

Hope this helps.

- Daniel.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top