Java File Exist isFileExists(String f, String ext)

Here you can find the source of isFileExists(String f, String ext)

Description

is File Exists

License

Open Source License

Declaration

public static File isFileExists(String f, String ext) 

Method Source Code


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

import java.io.*;

public class Main {
    public static File isFileExists(String f, String ext) {
        return isFileExists(new File(f), ext);
    }//from ww w .  j  ava  2s.  co  m

    public static File isFileExists(File f, String ext) {
        int point = f.getName().lastIndexOf('.');

        if (point == -1) {
            point = f.getName().length();
        }

        File lowerCasedFile = new File(f.getParentFile(),
                f.getName().substring(0, point) + "." + ext.toLowerCase());
        if (lowerCasedFile.exists()) {
            return lowerCasedFile;
        }

        File upperCasedFile = new File(f.getParentFile(),
                f.getName().substring(0, point) + "." + ext.toUpperCase());
        if (upperCasedFile.exists()) {
            return upperCasedFile;
        }

        return null;
    }
}

Related

  1. isFileExist(String sFileName)
  2. isFileExistByRegex(String dir, final String regex)
  3. isFileExisted(String filePathname)
  4. isFileExistent(String path)
  5. isFileExistNotCreate(String fileNameAndPath)
  6. isFileExists(String filePath)
  7. isFileExists(String filepath)
  8. isFileExists(String filePath)
  9. isFileExists(String filePathString)