import java.io.File; public class FileExample { public static void main(String[] args) { File file = new File("example.txt"); if(file.canRead()) { System.out.println("The file can be read."); } else { System.out.println("The file cannot be read."); } } }
import java.io.File; import java.io.IOException; public class FileExample { public static void main(String[] args) { File file = new File("example.txt"); try { if(file.canRead()) { System.out.println("The file can be read."); } else { System.out.println("The file cannot be read."); } } catch(IOException e) { e.printStackTrace(); } } }The package library for java.util File is "java.util".