javaFile类的使用

import java.io.File;
import java.io.IOException;
public class file {
	public static void main(String[] args) throws IOException {
	File  f=new File("E:\\Blog");
	printFile(f,0);//打印方法
}

	private static void printFile(File file, int level) {
		// TODO Auto-generated method stub
		for(int i=0;i<level;i++){
			System.out.print("-");
		}
		System.out.println(file.getName());
		if(file.isDirectory()){
			File[] files =file.listFiles();
			for(File temp:files){
				printFile(temp,level+1);//递归
			}
		}
	}
}

运行效果:
javaFile类的使用

相关文章:

  • 2021-06-08
  • 2021-11-10
  • 2021-08-29
  • 2021-09-30
  • 2021-06-29
  • 2021-07-23
  • 2021-09-19
  • 2021-04-02
猜你喜欢
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2021-12-27
  • 2021-10-12
相关资源
相似解决方案