Java File Delete delete(File f)

Here you can find the source of delete(File f)

Description

Accommodate Windows bug encountered in both Sun and IBM JDKs.

License

Apache License

Declaration

public static boolean delete(File f) 

Method Source Code


//package com.java2s;
/*//from  w w 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;

public class Main {
    /**
     * Accommodate Windows bug encountered in both Sun and IBM JDKs.
     * Others possible. If the delete does not work, call System.gc(),
     * wait a little and try again.
     */
    public static boolean delete(File f) {
        if (!f.delete()) {
            if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
                System.gc();
            }
            try {
                Thread.sleep(10);
                return f.delete();
            } catch (InterruptedException ex) {
                return f.delete();
            }
        }
        return true;
    }
}

Related

  1. delete(File f)
  2. delete(File f)
  3. delete(File f)
  4. delete(File f)
  5. delete(File f)
  6. delete(File f)
  7. delete(File f)
  8. delete(File f)
  9. delete(File f)