Here you can find the source of getFileNameList(String dir)
Parameter | Description |
---|---|
dir | a parameter |
public static List<String> getFileNameList(String dir)
//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(); } }