Java Canonical Path Create getCanonicalPath(String path)

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

Description

get Canonical Path

License

Open Source License

Declaration

private static String getCanonicalPath(String path) 

Method Source Code

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

import java.io.File;
import java.io.IOException;

public class Main {
    private static String getCanonicalPath(String path) {
        /**//from   ww  w  .  java 2s . c  o  m
         * @author HUANGTA
         * 1. Convert '.' to canonical path
         * 2. Add wrapping double quotes ("), otherwise path with space won't be recognized by CLI.
         */
        assert null != path && !path.isEmpty();
        try {
            String canonicalPath = new File(path).getCanonicalPath();
            if (path.endsWith(File.separator)) {
                canonicalPath = canonicalPath + File.separator;
            }
            return canonicalPath.contains(" ") ? String.format("\"%s\"",
                    canonicalPath) : canonicalPath;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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