0
I cant get this to work i keep getting this error "The method hasNext() is undefined for the type File"
import java.io.File; public class filesMain { public static void main(String[] args) { File x = new File("C:\\Users\\Lukas\\workspace\\Lol\\src\\files\\tal.txt"); if(x.hasNext()){ System.out.println("It is working"); } } }
2 ответов
+ 3
change x.hasNext() with x.exists() that will work
0
I believe "hasNext()" is a method of the iterator class (from which Scanner inherits). You would need to import the scanner class, as well as create a scanner object for the file you are looking at in order to use that method.