Java Delete Temp File deleteTempFile(File f)

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

Description

delete Temp File

License

Open Source License

Declaration

public static boolean deleteTempFile(File f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    private static List<String> tempFiles = Collections.synchronizedList(new ArrayList<String>());

    public static boolean deleteTempFile(File f) {
        if (f == null) {
            return false;
        }//  w  w w.ja va  2  s .  co  m
        f.deleteOnExit();
        f.delete();
        if (f.exists()) {
            return false;
        } else {
            try {
                tempFiles.remove(f.getCanonicalPath());
            } catch (IOException ioe) {
                tempFiles.remove(f.getAbsolutePath());
            }
            return true;
        }
    }
}

Related

  1. deleteTempFile()
  2. deleteTempFile(final File tempFile)
  3. deleteTempFile(String fileId)
  4. deleteTempFiles()
  5. deleteTempFiles()