---
title: "用java输出所有的文件"
author: "onlyor"
date: "2012-01-30T17:07:10Z"
tags: []
categories: ["开源软件"]
slug: "java"
draft: false
lastmod: "2012-01-30T17:08:34Z"
id: 1385603
url: "https://onlyor.iteye.com/blog/1385603"
---

public static void main(String args) {
		File file = new File("E:/wid7_sp/ExampleLibrary");
		fileSystemPath(file, 0);
	}
	
	// 输出
	public static void fileSystemPath(File file, int level) {
		StringBuffer sb = new StringBuffer();
		if(file.isFile()) {
			for(int i = 0; i<level; i++) {
				sb.append("--");
			}
			System.out.println(sb + file.getName());
		} else {
			for(int i = 0; i<level; i++) {
				sb.append("  ");
			}
			System.out.println(sb + file.getName());
			File fs = file.listFiles();
			if(null != fs && fs.length != 0) {
				for(File fl : fs) {
					fileSystemPath(fl, level + 1);
				}
			}
		}
	}