Java File Name Get getFileNameList(String dir)

Here you can find the source of getFileNameList(String dir)

Description

Get file name list under a directory

License

Apache License

Parameter

Parameter Description
dir a parameter

Declaration

public static List<String> getFileNameList(String dir) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//  w  ww. j ava2 s.  c  o  m
     * Get file name list under a directory
     *
     * @param dir
     * @return
     */
    public static List<String> getFileNameList(String dir) {
        List<String> fileNameList = new ArrayList<String>();
        File _dir = new File(dir);

        File[] files = _dir.listFiles();

        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    String fileName = files[i].getName();
                    fileNameList.add(fileName);
                }
            }
        }
        return fileNameList;
    }

    /**
     * Check if it is a valid file
     *
     * @param file
     * @return
     */
    public static boolean isFile(String file) {
        File f = new File(file);
        return f.exists() && f.isFile();
    }
}

Related

  1. getFileNameFromFilePath(String filepath)
  2. getFileNameFromFullPath(String fullPath)
  3. getFileNameFromZipEntry(ZipEntry entry)
  4. getFileNameInJCCTrayHome(String fileName)
  5. getFileNameList(File[] files)
  6. getFileNameList(String path)
  7. getFileNameNoSuffix(String fullName)
  8. getFileNameNoSuffix(String path)
  9. getFileNameOfPath(final String filePath)