Java Is Directory Valid isValidDirectory(String path)

Here you can find the source of isValidDirectory(String path)

Description

A simple check that the directory path is a valid one for the current OS.

License

Open Source License

Parameter

Parameter Description
path a parameter

Return

true if the given path is a valid one; false otherwise.

Declaration

public static boolean isValidDirectory(String path) 

Method Source Code

//package com.java2s;
/**/*from w ww  .  j a  v a2s. co  m*/
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.io.File;
import java.io.IOException;

public class Main {
    /**
     * A simple check that the directory path is a valid one for the current OS. The check does not test for existence
     * or write permissions, just for the path structure by using {@link File#getCanonicalPath()}.
     * 
     * @param path
     * @return <code>true</code> if the given path is a valid one; <code>false</code> otherwise.
     */
    public static boolean isValidDirectory(String path) {
        File file = new File(path);
        try {
            file.getCanonicalPath();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
}

Related

  1. isValidDirectory(File directory)
  2. isValidDirectory(File f)
  3. isValidDirectory(final File folder)
  4. isValidDirectory(String filePath)
  5. isValidDirectory(String name)