Java Directory Check checkDir(String dir, boolean mustWrite)

Here you can find the source of checkDir(String dir, boolean mustWrite)

Description

check Dir

License

Open Source License

Declaration

public static boolean checkDir(String dir, boolean mustWrite) throws IOException 

Method Source Code

//package com.java2s;
/**/*from w w  w  . j a va2 s.  com*/
 * Datei: URIHelper.java
 * Paket: de.beimax.testel.util
 * Projekt: TestEl
 *
 * Copyright (C) 2008 Maximilian Kalus.  All rights reserved.
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

import java.io.*;

public class Main {

    public static boolean checkDir(String dir, boolean mustWrite) throws IOException {
        File file = new File(dir);
        if (!file.exists())
            throw new IOException("Konnte Verzeichnis " + dir + " nicht finden!");
        if (!file.isDirectory())
            throw new IOException(dir + " ist kein Verzeichnis!");
        if (!file.canRead())
            throw new IOException("Verzeichnis " + dir + " ist nicht lesbar!");
        if (mustWrite && !file.canWrite())
            throw new IOException("Verzeichnis " + dir + " ist nicht beschreibbar!");
        return true;
    }

    /**Wie checkDir, aber mustWrite wird als true angenommen
     * @param dir
     * @return
     * @throws IOException
     */
    public static boolean checkDir(String dir) throws IOException {
        return checkDir(dir, true);
    }
}

Related

  1. checkDir(final String dirName)
  2. checkDir(final String name)
  3. checkDir(String dir)
  4. checkDir(String directory)
  5. checkDir(String dirName)
  6. checkDir(String name)
  7. checkDir(String path)