Java Canonical Path Create getCanonicalFile(final File file)

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

Description

Returns the canonical file for the file without throwing a checked exception.

License

Open Source License

Parameter

Parameter Description
file File to return the canonical file for or <code>null</code>.

Return

Canonical file for the given argument or null if the input was null.

Declaration

public static File getCanonicalFile(final File file) 

Method Source Code

//package com.java2s;
/**//from   w w w.  j av a  2  s. co m
 * Copyright (C) 2009 Future Invent Informationsmanagement GmbH. All rights
 * reserved. <http://www.fuin.org/>
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Returns the canonical file for the file without throwing a checked
     * exception. A potential {@link IOException} is converted into a
     * {@link RuntimeException}
     * 
     * @param file
     *            File to return the canonical file for or <code>null</code>.
     * 
     * @return Canonical file for the given argument or <code>null</code> if the
     *         input was <code>null</code>.
     */
    public static File getCanonicalFile(final File file) {
        if (file == null) {
            return null;
        }
        try {
            return file.getCanonicalFile();
        } catch (final IOException ex) {
            throw new RuntimeException("Couldn't get canonical file for: " + file, ex);
        }
    }
}

Related

  1. getCanonicalFile(File file)
  2. getCanonicalFile(File file)
  3. getCanonicalFile(File file)
  4. getCanonicalFile(File file)
  5. getCanonicalFile(File inFile)
  6. getCanonicalFile(final File file)
  7. getCanonicalFile(final File file)
  8. getCanonicalFileEL(File file)
  9. getCanonicalFileName(String filename)