mirror of
https://gitlab.com/harald.mueller/aktuelle.kurse.git
synced 2024-11-28 04:31:56 +01:00
28 lines
566 B
Java
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;
|
||
|
}
|
||
|
|
||
|
}
|