Here you can find the source of getFileList(String dir)
public static String[] getFileList(String dir)
//package com.java2s; /**//from w ww . j a va2 s .c o m * Copyright (c) 2015 https://github.com/zhaohuatai * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.io.File; import java.io.FilenameFilter; import java.util.regex.Pattern; public class Main { public static String[] getFileList(String dir) { try { File parent = new File(dir); if (!parent.isAbsolute() || !parent.isDirectory()) { return null; } return parent.list(); } catch (Exception e) { return null; } } public static String[] getFileList(final String dir, final String pattern) { try { File parent = new File(dir); if (!parent.isAbsolute() || !parent.isDirectory()) { return null; } final Pattern namePattern = Pattern.compile(pattern); return parent.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (namePattern.matcher(name).matches()) { return true; } else { return false; } } }); } catch (Throwable te) { return null; } } }