Java Canonical Path Create getCanonicalPath(String inPath)

Here you can find the source of getCanonicalPath(String inPath)

Description

get Canonical Path

License

Open Source License

Declaration

public static String getCanonicalPath(String inPath) 

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 String getCanonicalPath(String inPath) {
        return isBlank(inPath) ? inPath : getCanonicalFile(inPath, false).getAbsolutePath();
    }/*from  w w  w  .jav  a2  s.  c o m*/

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

    public static File getCanonicalFile(String inPath) {
        return getCanonicalFile(inPath, false);
    }

    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();
        }
    }
}

Related

  1. getCanonicalPath(final String path)
  2. getCanonicalPath(IPath fullPath)
  3. getCanonicalPath(IPath fullPath)
  4. getCanonicalPath(String basePath, String path)
  5. getCanonicalPath(String filePath, String prefix)
  6. getCanonicalPath(String name)
  7. getCanonicalPath(String outputPath)
  8. getCanonicalPath(String path)
  9. getCanonicalPath(String path)