-2

I have a folder and it has some xls files of same format in it. I don't know number of files or their names. I want to merge all of them. So how would i know the names of those files dynamically so that i can write further logic to merge them.

1 Answers1

0

Use following code

public static void main(String[] args) {
     ReadFile rf = new ReadFile();

     File[] files = new File("D:\\Foldername\\").listFiles();
     rf.showFiles(files);
}

public void showFiles(File[] files) {
    for (File file : files) {
        if (file.isDirectory()) {
            //Directory
            showFiles(file.listFiles()); // Calls same method again.
        } else {
            //File
            System.out.println(file.getName());
        }
    }
}
Vicky Thakor
  • 3,847
  • 7
  • 42
  • 67