File file = new File("example.txt"); if (file.exists()) { System.out.println("File exists!"); } else { System.out.println("File does not exist."); }
FileInputStream input = new FileInputStream("example.txt"); int data = input.read(); while (data != -1) { System.out.print((char)data); data = input.read(); } input.close();
FileOutputStream output = new FileOutputStream("example.txt"); String message = "Hello, world!"; output.write(message.getBytes()); output.close();In all of the above examples, we're utilizing the "java.io" package library to perform input/output operations.