-2

I am using java 7 but could upgrade to 8 if deemed worthwhile.

I am creating a program to compare files in 2 folders.

I am using Files.newDirectoryStream to extract the file data, although i have still to work out how to do that recursively, but I'm sure that should not be too difficult.

So to the point, I will do the compare and then add missing items so they are in sync.
This means I will need to store:

1) the name & 2) the path

Therefore I will need to use something to do this. I know I can do it with an Array[][]. But is this the best way to do this, or are lists more efficient.

I imagine the largest folder to hold 200 files.

Thanks in advance.

tryjava
  • 3
  • 1

1 Answers1

0

You can use ArrayList<File> which can be seen as a "Wrapper around plain arrays" (for the sake of simplicity and understanding). As each element in the List will be of type File, you will already have access to the path and name of the file and do not need to store them seperatly.

Of course the ArrayList has a bit more overhead then using simple arrays, but if you expect the largest amount to be 200 files, it's not a big deal and nothing to worry about. Except you run your program on your calculator ;)

If you can, you should first fetch the amount of files in your current working directory and use that number as initial size for the List:

int numberOfFiles = fetchFileCount(directory);
ArrayList<File> currentFiles = new ArrayList<>(numberOfFiles);
Korashen
  • 2,144
  • 2
  • 18
  • 28
  • I was using the array with the path type, but I'll look into using file to get out the filename and path. Thanks – tryjava Aug 09 '14 at 20:41