How to declare any ArrayList object of type File?
<p>I am trying to get the file names from a particular drive for eg: C:\ or D:\ etc. The File object is of type array and hence its not able to store lot of data in it. Need your advice on how i can store lots of file names in a File object. Below is my Code:</p>

<pre><code>public static void getContentsInDirectory(File directory) throws IOException{

    File[] listOfFiles = directory.listFiles();
    try{
        for(File file : listOfFiles){

            if(file.isDirectory()){
                System.out.println("It is a Directory:"+file);
                getContentsInDirectory(file);
            }
            else if(file.isFile()){
                System.out.println("File:   "+ file);
            }
        }   
    }
    catch(Exception e){
        e.printStackTrace();
    }
}
</code></pre>

<p>When i tried it with small size directories it worked well but when i give the whole drive like D: it throws Null Pointer Exception or sometimes Array IndexoutofBounds exception.</p>

<p>List listOfFiles = new ArrayList(); this </p>
