import org.apache.commons.lang.StringUtils; import java.io.File; import java.util.ArrayList; //读取文件夹下的所有文件名 public class ReadFileName { public static String path="D:\\output"; //需要读取的目录路径 public static void main(String[] args) { ArrayList str=getFileName(path); String list = StringUtils.join(str,","); System.out.println(list.replace(",","\n")); } public static ArrayList getFileName(String path) { ArrayList list = new ArrayList(); File f = new File(path); if (!f.exists()) { System.out.println(path + " not exists"); return list; } File fa[] = f.listFiles(); for (int i = 0; i < fa.length; i++) { File fs = fa[i]; list.add(fs.getName()); } return list; } }
如何快速获取目录下所有的文件名?学会这个java程序,轻松搞定,老板都要给你加薪!
最新推荐文章于 2024-09-04 15:29:36 发布