Q:

How to merge two File[] with different folders into a single File[] in Java

I'm trying to list files from two different directories in an Android device in order to upload them to a server. 
To do that, I'm getting the directory files under a File type and then throwing both listFiles() into correspondents File[] types.
    String d1 = Environment.getExternalStorageDirectory().getPath()+"/Download/";
    String d2 = Environment.getExternalStorageDirectory().getPath()+"/DCIM/Camera";

    File DirDocuments = new File(d1);
    File DirCamera = new File(d2);

    File[] ListDocuments = DirDocuments.listFiles();
    File[] ListCamera = DirCamera.listFiles();

I've tryed to merge then and uploadign using just a single "for" loop
    List<String> listTemp = new ArrayList<String>();

    for( int i=0; i< ListaDocuments.length; i++)
    {
            listTemp.add( ListaDocuments[i].getName() );
    }
    for( int i=0; i< ListaCamera.length; i++)
    {
            listTemp.add( ListaCamera[i].getName() );
    }

    File[] DirTotal = (String[]) listTemp.toArray(); //toArray gives Object[] and cannot be converted to File[], so I used String[]

But my app just stop and exits. What am I doing wrong? 
Do anyone knows how can I merge ListDocuments and ListCamera into a single File[]?
Thanks in advance. (sorry about my typos and bad english)

A:

You could join both arrays' contents into a List<File> and not a List<String>: 
    List<File> listTemp = new ArrayList<File>();

    for( int i=0; i< ListaDocuments.length; i++) {
            listTemp.add( ListaDocuments[i] );
    }
    for( int i=0; i< ListaCamera.length; i++)
    {
            listTemp.add( ListaCamera[i] );
    }

Notice there are other ways of joining those arrays (i.e. Apache Commons Collections ArrayUtils.addAll(T[], T...) as explained in How to concatenate two arrays in Java? and numerous duplicates).
And then just use the other version of toArray(): 
File[] DirTotal = listTemp.toArray(new File[0]);

toArray() without arguments will always return an Object[]. The version that takes an argument will fill up the passed array if it's big enough, and return a newly allocated array in case there's not enough room. The returned array is of the same type than the passed one, so if you pass a File[], you get a File[].

