Thursday, September 29, 2011

Get list of files in a directory using Java

While doing an automation I came up with a problem where I need to get a list of all files in a Directory.
So just though to share the same with you the program to do so. I had made used of recursion in the following programs to get the list of files. Following are the two programs one will give you a ArrayList of files with their absolute path where as another will give you an ArrayList of File object of respective files.
Following program will store the absolute path of all the files inside a directory to the fileList argument provided.

Following  program will store the File object of the files that are found into the respective fileList Array provided as an argument to the function

3 comments :

Unknown said...

Helpful and useful blog . I liked it very much .
Wemaketheapps

Chaitanya said...

Hi Varun,

I am trying to execute sample layout application provided with nativedriver. I am getting below error. Pl help

[2013-06-01 19:30:25 - simplelayout_Testing] Dx
trouble processing:
[2013-06-01 19:30:25 - simplelayout_Testing] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing com/google/android/testing/nativedriver/client/AdbConnection.class
...while processing com/google/android/testing/nativedriver/client/AdbConnection.class
[2013-06-01 19:30:25 - simplelayout_Testing] Dx
trouble processing:
[2013-06-01 19:30:25 - simplelayout_Testing] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing com/google/android/testing/nativedriver/client/AdbConnectionBuilder.class
...while processing com/google/android/testing/nativedriver/client/AdbConnectionBuilder.class
[2013-06-01 19:30:25 - simplelayout_Testing] Dx
trouble processing:
[2013-06-01 19:30:25 - simplelayout_Testing] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing com/google/android/testing/nativedriver/client/AdbException.class
...while processing com/google/android/testing/nativedriver/client

Varun Menon said...

Nativedriver is not maintained now and hence it may not work with updated selenium version or android apps. Please try to use Robotium for automation

Post a Comment