Java File Path Delete deleteFileWithSuffix(String path, String suffix)

Here you can find the source of deleteFileWithSuffix(String path, String suffix)

Description

Delete the file by a given file path with specific suffix.

License

Open Source License

Parameter

Parameter Description
path the file to be deleted
suffix the suffix

Return

true if delete successfully.

Declaration

public static boolean deleteFileWithSuffix(String path, String suffix) 

Method Source Code


//package com.java2s;
/*/*  w w w  . ja v a  2s.c o  m*/
 * RED: RNA Editing Detector Copyright (C) <2014> <Xing Li>
 *
 * RED is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * RED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * Delete the file by a given file path with specific suffix.
     *
     * @param path the file to be deleted
     * @param suffix the suffix
     * @return true if delete successfully.
     */
    public static boolean deleteFileWithSuffix(String path, String suffix) {
        boolean flag = false;
        File file = new File(path);
        if (file.isFile() && file.exists() && file.getName().endsWith(suffix)) {
            if (file.delete()) {
                flag = true;
            }
        }
        return flag;
    }
}

Related

  1. deleteFilesinPath(File pBaseDir, String pFileName)
  2. deleteFilesRecursive(final File path)
  3. deleteFileSystemDirectory(String dirPath)
  4. deleteFileSystemDirectory(String dirPath)
  5. deleteFileWithoutException(final String path)
  6. deleteFolder(File path)
  7. deleteFolder(File path)
  8. deleteFolder(String filePath)
  9. deleteFolder(String folderPath)