Java Directory Check checkDir(String pDir)

Here you can find the source of checkDir(String pDir)

Description

check Dir

License

Open Source License

Declaration

public static void checkDir(String pDir) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * /*w  w  w .j a  v a 2  s.co  m*/
 * Copyright 2007 Randall
 * 
 * This file is part of gomule.
 * 
 * gomule is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * gomule 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * gomlue; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 *  
 ******************************************************************************/

import java.io.*;

public class Main {
    public static void checkDir(String pDir) throws Exception {
        File lDir = new File(pDir);

        if (!lDir.exists()) {
            if (!lDir.mkdirs()) {
                throw new Exception("Can not create backup dir: " + pDir);
            }
        }
        if (!lDir.isDirectory()) {
            throw new Exception("File exists with name of backup dir: " + pDir);
        }
        if (!lDir.canRead()) {
            throw new Exception("Can not read backup dir: " + pDir);
        }
        if (!lDir.canWrite()) {
            throw new Exception("Can not write backup dir: " + pDir);
        }
    }
}

Related

  1. checkDir(String directory)
  2. checkDir(String dirName)
  3. checkDir(String name)
  4. checkDir(String path)
  5. checkDir(String path)
  6. checkDirAndCreate(File dir)
  7. checkDirCopy(File srcDir, File destDir)
  8. checkDirectory(File dir)
  9. checkDirectory(File directory)