Java File Exist isFileExist(String file)

Here you can find the source of isFileExist(String file)

Description

isFileExist method check file existance

License

Open Source License

Parameter

Parameter Description
file - full path file name

Return

true/false if file exists or does not exist

Declaration

public static boolean isFileExist(String file) 

Method Source Code

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

import java.io.File;

public class Main {
    /**//from   w  w w . j  av a 2s .com
     * isFileExist method check file existance
     * 
     * @param file - full path file name
     * @return true/false if file exists or does not exist
     */
    public static boolean isFileExist(String file) {
        File f = new File(file);
        if (f == null)
            return false;
        if (f.exists() && !f.isDirectory())
            return true;
        else
            return false;
    }

    public static boolean isDirectory(String trg, String str) {

        String tmp = str.substring(str.length() - 1, str.length());
        if (tmp.equals("/")) // directory check //$NON-NLS-1$
        {
            String dir = trg + File.separator
                    + str.substring(0, str.length() - 1);
            File fl = new File(dir);
            fl.mkdirs();
            return true;
        }
        return false;
    }
}

Related

  1. FileExistsNotEmpty(String filename)
  2. isFileExist(File file)
  3. isFileExist(File file, File folder)
  4. isFileExist(final String filePathString)
  5. isFileExist(String assetDestinationLocation, String id, String assetId)
  6. isFileExist(String fileNameAndPath)
  7. isFileExist(String filePath)
  8. isFileExist(String filePath)
  9. isFileExist(String path)