Why does the file return false for the isFile() method, even if it is a file. And when it is a directory, it returns false for isDirectory() . Am I doing something wrong? These files / directories that I am testing do not exist and I need to create them, so I am testing whether to use createFile() or mkdir() .
File file = new File("C:/Users/John/Desktop/MyDir/file.txt"); if(!file.exists()) { System.out.println("Is directory : " + file.isDirectory()); System.out.println("Is file : " + file.isFile()); }
java file
newbie
source share