This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm working on a project for school and part of it is to read from a txt file and convert to a bidimensional array.
Here is the code we created for that:
As you can see, we created a method to determine the size of the array (specially the number of rows) and another method to populate the array.
What bothers me is that we have to read the file twice, once for each method.
Is there a way that I can combine both so I read the file only once?
Read the file into a List<List<String>> or a List<String>, if you know in advance how many columns are contained in each row -- you'll probably want to use the ArrayList implementation of List -- then after populating the list, if you really need a bidimensional array you can generate it using List#toArray. But you probably shouldn't need that, it would be better to refactor your code to use the List<List> or List<String> instead.
There are no new questions, but there may be new answers.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Reading from a file to a bidimensional array