Example usage for java.io File listFiles

List of usage examples for java.io File listFiles

Introduction

In this page you can find the example usage for java.io File listFiles.

Prototype

public File[] listFiles(FileFilter filter) 

Source Link

Document

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:Main.java

public static void main(String[] args) {
    final String dir = "C:\\data\\projects\\";
    final Path path = Paths.get(dir);
    final File file = path.toFile();
    Stream.of(file.listFiles(File::isDirectory)).forEach(System.out::println);
    ;//from w  ww .  jav a2  s  .  c  o  m
}

From source file:MainClass.java

public static void main(String[] args) {

    File cwd = new File(System.getProperty("user.dir"));
    File[] htmlFiles = cwd.listFiles(new HTMLFileFilter());
    for (int i = 0; i < htmlFiles.length; i++) {
        System.out.println(htmlFiles[i]);
    }/* w  ww  . j a  v  a  2  s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println(// w  w  w .ja v  a2  s . c om
                "usage: java ClassFinder <class name>\n\n" + "example: java ClassFinder java.lang.String\n");
        System.exit(0);
    }

    File cwd = new File(".");
    File[] archives = cwd.listFiles(new ArchiveFilter());

    String classFileName = args[0].replace('.', '/');
    if (classFileName.endsWith(".class") == false) {
        classFileName += ".class";
    }

    System.out.println("Searching for " + classFileName + " ...");
    for (int j = 0; j < archives.length; j++) {
        // System.out.println("Searching " + archives[j].getName());
        if (searchJarFile(archives[j], classFileName)) {
            System.out.println("FOUND IN " + archives[j].getName());
        }
    }
}

From source file:org.jasig.portlet.data.Importer.java

public static void main(String[] args) throws Exception {
    String dir = args[0];/*from w  w  w .  j  a  v a  2  s. c  om*/
    String importExportContext = args[1];
    String sessionFactoryBeanName = args[2];
    String modelClassName = args[3];
    String serviceBeanName = args[4];
    String serviceBeanMethodName = args[5];

    ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext);
    SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class);
    Class<?> modelClass = Class.forName(modelClassName);
    Object service = context.getBean(serviceBeanName);

    JAXBContext jc = JAXBContext.newInstance(modelClass);

    File folder = new File(dir);
    File[] files = folder.listFiles(new ImportFileFilter());

    for (File f : files) {
        StreamSource xml = new StreamSource(f.getAbsoluteFile());
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement je1 = unmarshaller.unmarshal(xml, modelClass);
        Object object = je1.getValue();
        Session session = sessionFactory.getCurrentSession();
        Transaction transaction = session.beginTransaction();

        Method method = service.getClass().getMethod(serviceBeanMethodName, modelClass);
        method.invoke(service, object);
        transaction.commit();
    }
}

From source file:com.blogspot.devsk.l2j.geoconv.GeoGonv.java

public static void main(String[] args) {

    if (args == null || args.length == 0) {
        System.out.println("File name was not specified, [\\d]{1,2}_[\\d]{1,2}.txt will be used");
        args = new String[] { "[\\d]{1,2}_[\\d]{1,2}.txt" };
    }// w  ww.j  ava  2  s.  co  m

    File dir = new File(".");
    File[] files = dir.listFiles((FileFilter) new RegexFileFilter(args[0]));

    ArrayList<File> checked = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory() || file.isHidden() || !file.exists()) {
            System.out.println(file.getAbsoluteFile() + " was ignored.");
        } else {
            checked.add(file);
        }
    }

    if (OUT_DIR.exists() && OUT_DIR.isDirectory() && OUT_DIR.listFiles().length > 0) {
        try {
            System.out.println("Directory with generated files allready exists, making backup...");
            FileUtils.moveDirectory(OUT_DIR, new File("generated-backup-" + System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!OUT_DIR.exists()) {
        OUT_DIR.mkdir();
    }

    for (File file : checked) {
        GeoConvThreadFactory.startThread(new ParseTask(file));
    }
}

From source file:FileListFilter.java

public static void main(String[] args) {
    File myDir = new File("C:/");
    FilenameFilter select = new FileListFilter("F", "txt");
    File[] contents = myDir.listFiles(select);
    for (File file : contents) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file") + " last modified on\n"
                + new Date(file.lastModified()));
    }/*w  w  w.j  a v a  2 s .  c  o  m*/
}

From source file:JarSearcher.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println(/*from  ww w .  j  a v a2 s . c o m*/
                "usage: java ClassFinder <class name>\n\n" + "example: java ClassFinder java.lang.String\n");
        System.exit(0);
    }

    File cwd = new File(".");
    File[] archives = cwd.listFiles(new ArchiveFilter());

    String classFileName = args[0].replace('.', '/');
    if (classFileName.endsWith(".class") == false) {
        classFileName += ".class";
    }

    System.out.println("Searching for " + classFileName + " ...");
    for (int j = 0; j < archives.length; j++) {
        //      System.out.println("Searching " + archives[j].getName());
        if (searchJarFile(archives[j], classFileName)) {
            System.out.println("FOUND IN " + archives[j].getName());
        }
    }
}

From source file:disko.PDFDocument.java

public static void main(String[] args) {
    File dir = new File("/var/tmp/muriloq/mdc/selected");

    File[] pdfFiles = dir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".pdf");
        }//from  w  ww . java2s  .  co  m
    });

    for (File f : pdfFiles) {
        try {
            System.out.println(f.getName());
            PDFDocument pdf = new PDFDocument(f);
            pdf.getFullText();
            System.out.println(pdf.getFullText());
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

From source file:com.github.rinde.gpem17.Train.java

public static void main(String[] args) {
    if (args.length == 0) {
        run("files/config/gpem17.params");
    } else {//from  ww w. java 2  s .  c  om
        for (String file : args) {
            File f = new File(file);
            if (f.isDirectory()) {
                File[] paramFiles = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".params");
                    }
                });

                Arrays.sort(paramFiles, new Comparator<File>() {
                    @Override
                    public int compare(File o1, File o2) {
                        return o1.getName().compareTo(o2.getName());
                    }
                });

                for (File paramFile : paramFiles) {
                    run(paramFile.getPath());
                }
            } else {
                run(file);
            }
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File dir = new File("c:\\temp");
    FileFilter fileFilter = new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }/*w w w .  ja  v  a2  s . com*/
    };
    File[] files = dir.listFiles(fileFilter);

}