Java Canonical Path Create getCanonicalFile(File inFile)

Here you can find the source of getCanonicalFile(File inFile)

Description

Will return absolute file if not possible to determine the canonical file.

License

Open Source License

Parameter

Parameter Description
inFile a parameter

Declaration

public static File getCanonicalFile(File inFile) 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    public static File getCanonicalFile(String inPath) {
        return getCanonicalFile(inPath, false);
    }//from  w w  w . ja  v  a  2s. c  om

    public static File getCanonicalFile(String inPath, boolean inThrowRuntimeException) {
        return isBlank(inPath) ? null : getCanonicalFile(new File(inPath), inThrowRuntimeException);
    }

    /**
     * Will return absolute file if not possible to determine the canonical file.
     * 
     * Same as <code>getCanonicalFile(File inFile, boolean inThrowRuntimeException)</code> but parameter <code>inThrowRuntimeException</code> is set to <code>false</code> 
     * @param inFile
     * @return
     */
    public static File getCanonicalFile(File inFile) {
        return getCanonicalFile(inFile, false);
    }

    public static File getCanonicalFile(File inFile, boolean inThrowRuntimeException) {

        try {

            return inFile == null ? null : inFile.getCanonicalFile();

        } catch (final IOException e) {

            if (inThrowRuntimeException) {
                throw new RuntimeException(inFile == null ? "File is null" : e.getMessage(), e);
            }

            return inFile.getAbsoluteFile();
        }
    }

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

Related

  1. getCanonicalFile(File f)
  2. getCanonicalFile(File file)
  3. getCanonicalFile(File file)
  4. getCanonicalFile(File file)
  5. getCanonicalFile(File file)
  6. getCanonicalFile(final File file)
  7. getCanonicalFile(final File file)
  8. getCanonicalFile(final File file)
  9. getCanonicalFileEL(File file)