Java Folder Read getFiles(File directory)

Here you can find the source of getFiles(File directory)

Description

Scans a local directory for existing files.

License

Open Source License

Parameter

Parameter Description
directory a parameter
files a parameter

Declaration

public static List<String> getFiles(File directory) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/* ww  w  .ja  v  a2 s  . com*/
     * Scans a local directory for existing files.
     * 
     * @param directory
     * @param files
     */
    public static List<String> getFiles(File directory) {
        ArrayList<String> files = new ArrayList<String>();
        File[] filesInDir = directory.listFiles();
        for (int i = 0; i < filesInDir.length; i++) {
            File file = filesInDir[i];
            if (file.isFile()) {
                files.add(file.getName());
            }
        }
        return files;
    }

    /**
     * Deletes everything under a directory (including subdirectories)
     */
    public static List<String> getFiles(String dir) {
        return getFiles(new File(dir));

    }
}

Related

  1. getFiles(File dir)
  2. getFiles(File dir, File... excludes)
  3. getFiles(File dir, final String pattern)
  4. getFiles(File dir, String... names)
  5. getFiles(File directory)
  6. getFiles(File directory)
  7. getFiles(File directory)
  8. getFiles(File f, List response)
  9. getFiles(File file)