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"); } } }

20th Jun 2015, 11:50 AM
Lukas Schmidt
Lukas Schmidt - avatar
2 odpowiedzi
+ 3
change x.hasNext() with x.exists() that will work
16th Dec 2015, 1:06 PM
M'hamed Hicham RAHIMI
M'hamed Hicham RAHIMI - avatar
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.
15th Jan 2016, 6:58 PM
Alex Greidinger