Java Canonical Path Create getCanonicalFile(File file)

Here you can find the source of getCanonicalFile(File file)

Description

get Canonical File

License

Open Source License

Declaration

public static final File getCanonicalFile(File file) 

Method Source Code


//package com.java2s;

import java.io.File;

import java.io.IOException;

public class Main {
    public static final File getCanonicalFile(File file) {
        if (file == null)
            throw new IllegalArgumentException("file must not be null.");

        try {//from  ww w  .ja  v  a2  s .co m
            return (file.getCanonicalFile());
        } catch (IOException e) {
            return (file.getAbsoluteFile());
        }
    }

    /**
     * Returns the canonical representation of the given file using {@link File#getCanonicalFile()}.
     * If this fails, the result of {@link File#getAbsoluteFile()} is returned.
     * 
     * @param filename
     * 
     * @return the canonical representation of the given file.
     */
    public static final File getCanonicalFile(String filename) {
        return (getCanonicalFile(new File(filename)));
    }
}

Related

  1. getCanonicalCharsetQuiet(String charset)
  2. getCanonicalDirectory(final String rawDir)
  3. getCanonicalDirectory(String path, String errPrefix)
  4. getCanonicalFile(@Nullable final File aFile)
  5. getCanonicalFile(File f)
  6. getCanonicalFile(File file)
  7. getCanonicalFile(File file)
  8. getCanonicalFile(File file)
  9. getCanonicalFile(File inFile)