-2

i'm developing a DMS. i'm currently working on the document management system aspect , like Managing PDFs and Docs;

Now I want my application to be able to show all the existing PDF and DOC files on the computer in my application. so that they can be opened when the user clicks on them.

i'm currently just focusing on PDFs And Docs

Adrino
  • 17
  • 2

1 Answers1

0
import java.io.File;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;


public class SearchDocFiles {
    public static String[] EXTENSIONS = { "doc", "docx" };

    public Collection<File> searchFilesWithExtensions(final File directory, final String[] extensions) {
         return FileUtils.listFiles(directory,
                                    extensions,
                                    true);
     }


    public static void main(String... args) {


         Collection<File> documents = new SearchDocFiles().searchFilesWithExtensions(
                    new File("/path/to/document/folder"),
                    SearchDocFiles.EXTENSIONS);
            for (File document: documents) {
                System.out.println(document.getName() + " - " + document.length());
            }
        }
    }

this uses Apache Commons IO expectially FileUtil

suulisin
  • 1,414
  • 1
  • 10
  • 17