Here you can find the source of getCanonicalDirectory(final String rawDir)
Parameter | Description |
---|---|
rawDir | a path in any legal form, such as a relative path |
public static String getCanonicalDirectory(final String rawDir) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { /**// ww w. j av a 2 s .co m * If the given string is the empty string, then the result is the current directory. * * @param rawDir a path in any legal form, such as a relative path * @return the absolute and unique path in String */ public static String getCanonicalDirectory(final String rawDir) throws IOException { String dir = rawDir.length() == 0 ? "." : rawDir; // create working dir if necessary File dd = new File(dir); if (!dd.exists()) { dd.mkdirs(); } if (!dir.startsWith("/")) { dir = dd.getCanonicalPath(); } return dir; } }