package com.heima.ch;
import java.io.File;
import java.util.Scanner;
public class Tset1 {
/**
* * 需求:1,从键盘接收一个文件夹路径,统计该文件夹大小
*/
public static void main(String[] args) {
File dir = getFile();
System.out.println(printFile(dir));
}
public static long printFile(File dir) {
File[] files = dir.listFiles();
long len =0 ;
for (File file : files) {
if(file.isFile()){
len = len + file.length();
}else{
printFile(file);
}
}
return len;
}
public static File getFile() {
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("111111");
String line = sc.nextLine();
File file = new File(line);
if(!file.exists()){
System.out.println("不cz文件");
}else if(file.isFile()){
System.out.println("是文件");
}else{
return file;
}
}
}
}
|
|