---
title: "java读取某目录下所有文件名"
author: "harbey"
date: "2009-09-29T15:22:29Z"
tags: []
slug: "java"
draft: false
lastmod: "2009-09-29T15:22:29Z"
id: 480358
url: "https://harbey.iteye.com/blog/480358"
---

Java的Flie对象的list方法可以获取该目录下的所有文件名集合；
如下是通过list方法获取文件名后再针对特定的文件名进行处理：

```java

// 文件目录
String path = "";
File file = new File(path);
		String[] fns = file.list(new FilenameFilter() {
			public boolean accept(File dir, String name) {
				if (name.startsWith(prefix)) {
					return true;
				} else {
					return false;
				}
			}
		});

```