---
title: "列出某文件夹下的所以文件 "
author: "phoebird"
date: "2010-07-14T20:15:02Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-07-14T20:15:02Z"
id: 712891
url: "https://phoebird.iteye.com/blog/712891"
---

```
package org.lcj.demo;
import java.io.File;
public class ListFiles {
public static void main(String[] args) {
  File file = new File("D:" + File.separator + "Downloads");// 通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。
  fun(file);
}
public static void fun(File file) {
  if (file.isDirectory()) {
   File f[] = file.listFiles();//返回一个抽象路径名数组，这些路径名表示此抽象路径名表示的目录中的文件。
   if (f != null) {
    for (int x = 0; x < f.length; x++) {
     fun(f[x]);
    }
   }
  } else {
   System.out.println(file);
  }
}
}
```