tags:

views:

64

answers:

3

The directoryReader gets you dirs in current dir in File[]-format.

Code

DirectoryReader data = new DirectoryReader();
File[] dirs = data.getDirsInDir(".");
File[] dirsMore = data.getDirsInDir("..");

// How can I append dirsMore to dirs-file[]?
A: 
List<File> aList = Arrays.asList(dirs);
List<File> bList = Arrays.asList(dirsMore);

aList.addAll(bList);  // a has all elements
Wajdy Essam
I'm pretty sure a List you get from Arrays.asList can't be appended to.
Paul Tomblin
thanks , im tried it now and it make exception : java.lang.UnsupportedOperationException
Wajdy Essam
+1  A: 

You can't append to an array. The simplest way is to put the array into a Collection, do an "addAll" to the other array, and then use "toArray" on the Collection.

List<File> fileList = new ArrayList<File>();
fileList.addAll(dirs);
fileList.addAll(dirsMore);

File[] allDirs = fileList.toArray(new File[0]);
Paul Tomblin
A: 
    File[] concat(File[] A, File[] B) 
   {
     File[] C= new File[A.length+B.length];
     System.arraycopy(A, 0, C, 0, A.length);
     System.arraycopy(B, 0, C, A.length, B.length);
     return C;
   }

Heres the doc for java's arraycopy() method.

Zaki