Created
June 29, 2011 10:50
-
-
Save DNNX/1053633 to your computer and use it in GitHub Desktop.
Checks if directory exists and readable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
public class DirectoryChecker | |
{ | |
public static boolean isWindows() | |
{ | |
String os = System.getProperty("os.name").toLowerCase(); | |
return os.indexOf("windows") != -1; | |
} | |
public static boolean canRead(File directory) | |
{ | |
if (!isWindows()) | |
return directory.canRead(); | |
File testFolder = new File(directory, "TestFolder"); | |
return testFolder.mkdir() && testFolder.delete(); | |
} | |
public static void main(String[] args) | |
{ | |
String dirName = args.length == 0 ? "." : args[0]; | |
File directory = new File(dirName); | |
System.out.println(dirName + " exists: " + directory.exists()); | |
System.out.println(dirName + " is directory: " + directory.isDirectory()); | |
System.out.println(dirName + " can be read: " + canRead(directory)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile:
javac DirectoryChecker.java
Run:
java DirectoryChecker "\\ipaddress\path\to\your\dir\"
or
java DirectoryChecker "c:\test"