Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Reading array of unknown size from file to array

Thread view: 
Denis Palas - 19 Dec 2006 16:38 GMT
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
bugbear - 19 Dec 2006 16:49 GMT
> Dear All
>
[quoted text clipped - 10 lines]
> 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
Daniel Pitts - 19 Dec 2006 23:14 GMT
> Dear All
>
[quoted text clipped - 13 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.