Java Utililty Methods Canonical Path Create

List of utility methods to do Canonical Path Create

Description

The list of methods to do Canonical Path Create are organized into topic(s).

Method

StringgetCanonicalCharset(String charset)
get Canonical Charset
return new OutputStreamWriter(DUMMY_OUTPUT_STREAM, charset).getEncoding();
StringgetCanonicalCharsetQuiet(String charset)
get Canonical Charset Quiet
try {
    return getCanonicalCharset(charset);
} catch (UnsupportedEncodingException e) {
    return null;
StringgetCanonicalDirectory(final String rawDir)
If the given string is the empty string, then the result is the current directory.
String dir = rawDir.length() == 0 ? "." : rawDir;
File dd = new File(dir);
if (!dd.exists()) {
    dd.mkdirs();
if (!dir.startsWith("/")) {
    dir = dd.getCanonicalPath();
return dir;
FilegetCanonicalDirectory(String path, String errPrefix)
Retrieves the canonicalized directory from the specified path.
File rc;
try {
    rc = new File(path).getCanonicalFile();
} catch (IOException e) {
    throw new IllegalArgumentException(errPrefix + " '" + path + "' : " + e.getMessage()); 
if (!rc.exists()) {
    throw new IllegalArgumentException(errPrefix + " '" + path + "' : does not exist"); 
...
FilegetCanonicalFile(@Nullable final File aFile)
Get the canonical file of the passed file, if the file is not null.
return aFile == null ? null : aFile.getCanonicalFile();
FilegetCanonicalFile(File f)
get Canonical File
try {
    return f.getCanonicalFile();
} catch (IOException e) {
    return f.getAbsoluteFile();
FilegetCanonicalFile(File file)
get Canonical File
return file.getCanonicalFile();
FilegetCanonicalFile(File file)
get Canonical File
try {
    return file.getCanonicalFile();
} catch (IOException e) {
    throw new RuntimeException(
            "Failed to get canonical file for absolute path [" + file.getAbsolutePath() + "].", e);
FilegetCanonicalFile(File file)
get Canonical File
file = new File(file.getPath());
File result;
try {
    result = file.getAbsoluteFile().getCanonicalFile();
} catch (IOException e) {
    result = file.getAbsoluteFile();
return result;
...
FilegetCanonicalFile(File file)
get Canonical File
if (file == null)
    throw new IllegalArgumentException("file must not be null.");
try {
    return (file.getCanonicalFile());
} catch (IOException e) {
    return (file.getAbsoluteFile());