Java tutorial
//package com.java2s; /* * Hewlett-Packard Company * All rights reserved. * * This file, its contents, concepts, methods, behavior, and operation * (collectively the "Software") are protected by trade secret, patent, * and copyright laws. The use of the Software is governed by a license * agreement. Disclosure of the Software to third parties, in any form, * in whole or in part, is expressly prohibited except as authorized by * the license agreement. */ import android.content.Context; import android.content.ContextWrapper; import java.io.File; public class Main { private static final int MAXFILEAGE = (int) 3600000L; public static final String IMAGE_DIR = "imageDir"; private static Context c; protected static void cleanUpFileDirectory() { if (c == null) // no application context exists return; ContextWrapper cw = new ContextWrapper(c.getApplicationContext()); File directory = cw.getDir(IMAGE_DIR, Context.MODE_PRIVATE); File file[] = directory.listFiles(); for (int i = 0; i < file.length; i++) { if (file[i].lastModified() + MAXFILEAGE < System.currentTimeMillis()) { file[i].delete(); } } } }