Here you can find the source of getCanonicalPath(String path)
private static String getCanonicalPath(String path)
//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); } } }