Java File isFile() Method
Example
Check if a file and a folder are normal files:
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
File myFile = new File("filename.txt");
myFile.createNewFile();
File myFolder = new File("myFolder");
myFolder.mkdir();
System.out.println(myFile.isFile());
System.out.println(myFolder.isFile());
}
}
Definition and Usage
The isFile() method checks if the path points to a normal file.
It returns false for a directory (folder), and for a path that does not exist.
Tip: Use the isDirectory() method to check if the path is a directory.
Syntax
public boolean isFile()
Parameter Values
None.
Technical Details
| Returns: | true if the path is a normal file that exists, otherwise false. |
|---|
Related Pages
❮ File Methods