1

I've seen many links to do the opposite of this but that is not what I want. I want to make an array and the contents of the array I want to equal the file, so they can be read one at a time in a loop but what I've shown below is what I have come up with at the moment, but have no idea how to get right.

File (lifeobjects[5]) = new File ("toad.lif");

EDIT: I want to read a file from an array not into one. The array just points to the file to be read. and I have a string array called lifeobjects which I want the files to be in.

EDIT: All this array does is list the files, after that a for loop will get each file one at a time, read them and the contents will go into another array. To make java realize that each element of the array is a file is where I am getting stuck. The one line of code I have is one of many after the String array which is where the list of file names are found.

EDIT: Ok I've managed to get it working, All I needed to do was change the array elements and add their file extensions to them and the code above wasn't needed at all, sorry if the question was too vague, had hard time explaining it. All I have to do now is convert this command line program to a GUI with a square grid, I'll ask that question next as I have tried and tried and got nowhere.

nh1402
  • 75
  • 1
  • 9
  • 2
    What is that? What you are asking is kind of wierd. Can you please elaborte – Adel Boutros Jan 06 '12 at 17:52
  • It's unclear what you're trying to do. Reading a file into a list of lines is trivial; use [Commons-IO `FileUtils.readLines`](http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html#readLines(java.io.File)). (There's also an iterator.) Are you trying to read in objects? – Dave Newton Jan 06 '12 at 18:02
  • Are you looking to put the file in line-by-line in an array, or each file into its own place in the array? The former is accomplished with `Scanner.readLine()` and a loop, and the latter is *extremely* wasteful with memory. – Makoto Jan 06 '12 at 18:02

1 Answers1

0

If I understand your question correctly:

File[] lifeobjects = new File[5];
lifeobjects[0] = new File("toad.lif");
lifeobjects[1] = new File("toad2.lif");
...
lifeobjects[4] = new File("toad5.lif");
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111