Java Delete File deleteFile(File file)

Here you can find the source of deleteFile(File file)

Description

delete File

License

Open Source License

Declaration

public static void deleteFile(File file) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed 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
 *******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    public static void deleteFile(File file) throws IOException {
        if (file == null || !file.exists()) {
            return;
        }//w  w w  .  j  a v a  2s  . c  o  m

        if (!file.delete()) {
            throw new IOException("Can't delete file : " + file.getPath());
        }
    }

    /**
     * Gets the path name for a given file name
     * 
     * @param   file    The file name to process
     * @return  The name of the path to the given file
     */
    public static String getPath(File file) {
        return getPath(file.toString());
    }

    /**
     * Gets the path name for a given file name
     * 
     * @param   file    The file name to process
     * @return  The name of the path to the given file
     */
    public static String getPath(String file) {

        //  return StringUtils.getLeftLast(file, "/") + "/";
        return "";
    }
}

Related

  1. deleteFile(File file)
  2. deleteFile(File file)
  3. deleteFile(File file)
  4. deleteFile(File file)
  5. deleteFile(File file)
  6. deleteFile(File file)
  7. deleteFile(File file)
  8. deleteFile(File file)
  9. deleteFile(File source)