Java tutorial
//package com.java2s; import java.io.File; public class Main { private static void cleanDir(File dir, long bytes) { long bytesDeleted = 0; File[] files = dir.listFiles(); for (File file : files) { bytesDeleted += file.length(); file.delete(); if (bytesDeleted >= bytes) { break; } } } }