Java File Object Create toFile(String inFile)

Here you can find the source of toFile(String inFile)

Description

to File

License

Open Source License

Declaration

public static File toFile(String inFile) 

Method Source Code

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

import java.io.File;

public class Main {
    public static File toFile(String inFile) {
        return toFile(inFile, true, true);
    }/*from   w  w w . j  av  a  2  s .c o  m*/

    public static File toFile(String inFile, boolean inReturnFile, boolean inReturnDir) {

        if (isBlank(inFile)) {
            return null;
        }
        final File f = new File(inFile);

        if (inReturnFile == false && isFile(f)) {
            return null;
        }
        if (inReturnDir == false && isDir(f)) {
            return null;
        }

        return f;
    }

    public static boolean isBlank(String inValue) {
        return inValue == null || inValue.trim().isEmpty();
    }

    public static boolean isFile(File inFile) {
        return inFile != null && inFile.isFile();
    }

    public static boolean isFile(String inFilePath) {
        return isNotBlank(inFilePath) && isFile(new File(inFilePath));
    }

    /**
     * Same as isDirectory()
     * @param inDir
     * @return
     */
    public static boolean isDir(File inDir) {
        return inDir != null && inDir.isDirectory();
    }

    public static boolean isDir(String inDirPath) {
        return isNotBlank(inDirPath) && isDir(new File(inDirPath));
    }

    public static boolean isNotBlank(String inValue) {
        return !isBlank(inValue);
    }

    public static boolean isDirectory(File inDir) {
        return isDir(inDir);
    }

    public static boolean isDirectory(String inDir) {
        return isDir(inDir);
    }
}

Related

  1. toFile(String context, String fileName, boolean append)
  2. toFile(String fileName)
  3. toFile(String fileName, String content)
  4. toFile(String fileName, String cwd)
  5. toFile(String fileName, String txt)
  6. toFile(String line)
  7. toFile(String path)
  8. toFile(String path)
  9. toFile(String path)