Here you can find the source of getAllFileNamesByPath(String path)
Parameter | Description |
---|---|
path | String folder path |
public static String[] getAllFileNamesByPath(String path)
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.*; public class Main { /**/*from w ww. j a v a 2s .c o m*/ * get all file names in a folder * * @param path String folder path * @return String[] */ public static String[] getAllFileNamesByPath(String path) { File file = new File(path); if (!file.exists()) { return null; } if (!file.isDirectory()) { return null; } String[] tempList = file.list(); List<String> fileList = new ArrayList<String>(); File tempFile; for (String fileName : tempList) { if (path.endsWith(File.separator)) { tempFile = new File(path + fileName); } else { tempFile = new File(path + File.separator + fileName); } if (tempFile.isFile()) { fileList.add(tempFile.getName()); } } return fileList.toArray(new String[fileList.size()]); } }