aktuelle.kurse/oldies/m411/docs/Daten-Uebungen-CodeBeispiele/Rekursion/DiskUsage.java
Müller Harald 3fdacd20c0 muh
2022-07-28 09:14:44 +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;
}
}