Skip to content

Instantly share code, notes, and snippets.

@DNNX
Created June 29, 2011 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNNX/1053633 to your computer and use it in GitHub Desktop.
Save DNNX/1053633 to your computer and use it in GitHub Desktop.
Checks if directory exists and readable
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));
}
}
@DNNX
Copy link
Author

DNNX commented Jun 29, 2011

Compile:
javac DirectoryChecker.java

Run:
java DirectoryChecker "\\ipaddress\path\to\your\dir\"
or
java DirectoryChecker "c:\test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment