javaclasscannot-find-symbol

Why I am getting error "cannot find symbol" when I would like to use java.io.File class?


I'd like to use isDirectory() method (java.io.File class). I created a simple test code to try out this method, however I always get a 'cannot find symbol' error.

My code:

import java.io.File;

public class MyUtils {
    public static void main(String[] args) {
        String path = "/this/is/not/a/valid/path";
        boolean ValidPath = path.isDirectory();
        System.out.println(ValidPath);
    }
}

Solution

  • Because your path is a String object. You may instantiate a File object with the path String:

    boolean ValidPath = new File(path).isDirectory();