Here you can find the source of getCanonicalDirectory(String path, String errPrefix)
Parameter | Description |
---|---|
path | the path to test |
errPrefix | a String to use to provide a specific error message |
Parameter | Description |
---|---|
IllegalArgumentException | if there is an IOException accessing the directory orif the path does not exist or if the path is not a directory |
public static File getCanonicalDirectory(String path, String errPrefix)
//package com.java2s; /**/*ww w . j a v a2s . c o m*/ * Copyright (c) 2009 Stephen Evanchik * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Stephen Evanchik - initial implementation */ import java.io.File; import java.io.IOException; public class Main { /** * Retrieves the canonicalized directory from the specified path. * * @param path * the path to test * @param errPrefix * a String to use to provide a specific error message * @return the canonicalized {@link File} * * @throws IllegalArgumentException * if there is an {@link IOException} accessing the directory or * if the path does not exist or if the path is not a directory */ public static File getCanonicalDirectory(String path, String errPrefix) { File rc; try { rc = new File(path).getCanonicalFile(); } catch (IOException e) { throw new IllegalArgumentException(errPrefix + " '" + path + "' : " + e.getMessage()); //$NON-NLS-1$ $NON-NLS-2$ } if (!rc.exists()) { throw new IllegalArgumentException(errPrefix + " '" + path + "' : does not exist"); //$NON-NLS-1$ $NON-NLS-2$ } if (!rc.isDirectory()) { throw new IllegalArgumentException(errPrefix + " '" + path + "' : is not a directory"); //$NON-NLS-1$ $NON-NLS-2$ } return rc; } }