Java Folder Read getFiles(String path)

Here you can find the source of getFiles(String path)

Description

Returns the files laid in the specified folder path

License

Open Source License

Parameter

Parameter Description
path path of the folder

Return

the files laid in the specified folder path

Declaration

public static File[] getFiles(String path) 

Method Source Code


//package com.java2s;
/*//w w w.ja va2s. c om
 * Copyright (c) 2010-2012 Zhao.Xiang<z405656232x@163.com> Holding Limited.
 * All rights reserved.
 * 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.io.FileFilter;

public class Main {
    /**
     * Returns the files laid in the specified folder path
     * 
     * @param path
     *          path of the folder
     * @return the files laid in the specified folder path
     */
    public static File[] getFiles(String path) {
        if (isDirectory(path)) {
            File file = new File(path);
            return file.listFiles(new FileFilter() {
                @Override
                public boolean accept(File file) {
                    if (file.getName().startsWith(".")) {
                        return false;
                    }

                    /*
                    if (!file.isDirectory() && !file.getName().endsWith(".xml"))
                    {
                       return false;
                    }
                    */

                    return true;
                }
            });
        }
        return null;
    }

    /**
     * Returns true if the specified path is directory
     * 
     * @param path
     *          path of the folder
     * @return true if path is directory; false otherwise
     */
    public static boolean isDirectory(String path) {
        File file = new File(path);
        return file.isDirectory();
    }
}

Related

  1. getFiles(String path)
  2. getFiles(String path)
  3. getFiles(String path)
  4. getFiles(String PATH)
  5. getFiles(String path)
  6. getFiles(String path)
  7. getFiles(String path, final String suffix)
  8. getFiles(String path, String endian)
  9. getFiles(String paths)