Here you can find the source of getFileNames_STR(String path)
public static String[] getFileNames_STR(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static String[] getFileNames_STR(String path) { List<File> al = getFiles(path); String[] fl = null;// w w w . j a va2s.com if (al != null && !al.isEmpty()) { fl = new String[al.size()]; for (int i = 0; i < al.size(); i++) { fl[i] = al.get(i).getName(); } } return fl; } /** * getFiles * * @param path * @return */ public static List<File> getFiles(String path) { File dir = new File(path); if (dir.exists()) { File[] files = dir.listFiles(); if (files != null && files.length > 0) { return initDirs(files); } } return Collections.emptyList(); } /** * existFile * * @param path * @return */ public static boolean exists(String path) { try { File temp = new File(path); return temp.exists(); } catch (Exception e) { // ignore } return false; } public static List<File> initDirs(File[] files) { ArrayList<File> dirs = new ArrayList<File>(); for (int i = 0; i < files.length; i++) { if (files[i].isFile() || files[i].isDirectory()) { dirs.add(files[i]); } } return dirs; } /** * isFile * * @param path * @return */ public static boolean isFile(String path) { File file = new File(path); if (file.exists() && file.isFile()) { return true; } return false; } }