aktuelle.kurse/old_m411/docs/Daten-Uebungen-CodeBeispiele/Rekursion/DiskUsage.java
Müller Harald 507e5da390 muh
2022-05-13 11:53:50 +02:00

28 lines
566 B
Java

package recusion;
import java.io.File;
public class DiskUsage {
public static void main(String[] args) {
long size = diskUsage(new File("/users/capa/tmp"));
System.out.println("Total size is [" + size + "] Bytes.");
}
public static long diskUsage(File f) {
long diskUsage = 0;
if (f.isFile()) { diskUsage = f.length(); }
System.out.println("Checking " + f);
if (f.isDirectory()) {
File[] fileList = f.listFiles();
if (fileList != null) {
for (File g : fileList) {
diskUsage += diskUsage(g);
}
}
}
return diskUsage;
}
}