Java Utililty Methods Directory Check

List of utility methods to do Directory Check

Description

The list of methods to do Directory Check are organized into topic(s).

Method

voidcheckDirAndCreate(File dir)
Checks a directory for existence and creates it if non-existent.
if (!dir.exists())
    dir.mkdirs();
voidcheckDirCopy(File srcDir, File destDir)
check Dir Copy
if (!srcDir.exists()) {
    throw new FileNotFoundException("Source '" + srcDir + "' does not exist.");
if (!srcDir.isDirectory()) {
    throw new IOException("Source '" + srcDir + "' is not a directory.");
if (equals(srcDir, destDir)) {
    throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same.");
...
voidcheckDirectory(File dir)
Check local directory.
if (!dir.exists())
    if (!dir.mkdirs())
        throw new IllegalArgumentException("!dir.mkdirs(), dir=" + dir);
if (!dir.isDirectory())
    throw new IllegalArgumentException("dir (=" + dir + ") is not a directory.");
voidcheckDirectory(File directory)
check Directory
if (!directory.isDirectory()) {
    throw new IllegalArgumentException(directory.getAbsolutePath() + " is not a directory");
voidcheckDirectory(File directory)
Checks that the given File exists and is a directory.
if (!directory.exists()) {
    throw new IllegalArgumentException(directory + " does not exist");
if (!directory.isDirectory()) {
    throw new IllegalArgumentException(directory + " is not a directory");
voidcheckDirectory(File directory)
check Directory
if (!directory.exists() && !directory.mkdirs()) {
    throw new IOException("Could not create directory! " + directory);
if (!directory.isDirectory()) {
    throw new IOException("Directory is not a directory! " + directory);
if (!directory.canRead() || !directory.canWrite()) {
    throw new IOException("Can not read from or write into directory! " + directory);
...
voidcheckDirectory(File directory, String pckgname, ArrayList> classes)
Private helper method
File tmpDirectory;
if (directory.exists() && directory.isDirectory()) {
    final String[] files = directory.list();
    for (final String file : files) {
        if (file.endsWith(".class")) {
            try {
                classes.add(Class.forName(pckgname + '.' + file.substring(0, file.length() - 6)));
            } catch (final NoClassDefFoundError e) {
...
FilecheckDirectory(File file)
Checks that the provided directory path refers to an existing/readable directory.
String directoryPath = file.getPath();
File inDir = file;
if (!inDir.isDirectory()) {
    throw new IllegalArgumentException("Not a directory: " + directoryPath);
if (!inDir.canRead()) {
    throw new IllegalArgumentException("Not a writable directory: " + directoryPath);
try {
    directoryPath = inDir.getCanonicalPath();
} catch (IOException e) {
    throw new IllegalArgumentException(e);
inDir = new File(directoryPath);
if (!inDir.isDirectory()) {
    throw new IllegalArgumentException("Not a directory: " + directoryPath);
if (!inDir.canRead()) {
    throw new IllegalArgumentException("Not a writable directory: " + directoryPath);
return new File(directoryPath);
voidcheckDirectory(File target)
check Directory
if (target == null) {
    throw new IllegalArgumentException("argument must not be null.");
if (target.isFile()) {
    throw new IllegalArgumentException("argument must be directory. [" + target.getAbsolutePath() + "]");
voidcheckDirectory(final File directory)
check Directory
if (directory.exists()) {
    if (!directory.isDirectory()) {
        throw new IOException(directory + " is not a directory");
} else {
    throw new IOException(directory + " doesn't exist");