Java tutorial
//package com.java2s; import java.io.File; public class Main { public static void deleteFiles(String path, String excludeSuffix) { File dir = new File(path); File[] files = dir.listFiles(); if (files != null && files.length > 0) { for (File file : files) { if (excludeSuffix != null && file.getName().contains(excludeSuffix)) { continue; } file.delete(); } } } }