Here you can find the source of deleteTempFiles()
public static void deleteTempFiles() throws IOException
//package com.java2s; /*//from ww w . ja v a 2 s. c om * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.UUID; public class Main { private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "aether-" + UUID.randomUUID().toString().substring(0, 8)); public static void deleteTempFiles() throws IOException { deleteFile(TMP); } public static void deleteFile(File file) throws IOException { if (file == null) { return; } Collection<File> undeletables = new ArrayList<File>(); delete(file, undeletables); if (!undeletables.isEmpty()) { throw new IOException("Failed to delete " + undeletables); } } private static void delete(File file, Collection<File> undeletables) { String[] children = file.list(); if (children != null) { for (String child : children) { delete(new File(file, child), undeletables); } } if (!del(file)) { undeletables.add(file.getAbsoluteFile()); } } private static boolean del(File file) { for (int i = 0; i < 10; i++) { if (file.delete() || !file.exists()) { return true; } } return false; } }