Java Utililty Methods Is Legal File Path

List of utility methods to do Is Legal File Path

Description

The list of methods to do Is Legal File Path are organized into topic(s).

Method

booleanisLegalDir(final String dirname)
Proves if the argument points to a existent directory (not file!).
final File f = new File(dirname);
if (!f.exists()) {
    return false;
if (f.isFile()) {
    return false;
return true;
...
booleanisLegalFile(String filePath)
is Legal File
File file = new File(filePath);
if (!file.exists() || file.isDirectory() || !file.canRead()) {
    return false;
return true;
booleanisLegalFilePath(File inBasePath, File inResourcePath)
check if the resource path is a subpath of the basepath
try {
    return inResourcePath.getCanonicalPath().startsWith(inBasePath.getCanonicalPath());
} catch (final Exception e) {
    return false;