import java.io.*; public class WriteBooleanExample { public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("output.txt"); DataOutputStream dos = new DataOutputStream(fos); boolean b = true; dos.writeBoolean(b); dos.close(); fos.close(); } }
import java.io.*; public class ReadBooleanExample { public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("output.txt"); DataInputStream dis = new DataInputStream(fis); boolean b = dis.readBoolean(); System.out.println("Boolean value: " + b); dis.close(); fis.close(); } }In this example, a boolean value is read from a file using the readBoolean() method. This method is part of the java.io package library.