package cusack; import java.io.PrintWriter; import java.io.IOException; import java.util.Scanner; public class PX_CreateFileHardCoded_lastname { public static void main(String[] args) { // Hard-coded file name and text content String fileName = "input.dat"; String data = "This is line containing data in it."; // Use Scanner to simulate reading the text line by line Scanner scanner = new Scanner(data); try { // Create the file PrintWriter writer = new PrintWriter(fileName); // Write each line from the Scanner to the file while (scanner.hasNextLine()) { writer.println(scanner.nextLine()); } // Close both scanner and writer scanner.close(); writer.close(); System.out.println("File '" + fileName + "' created successfully!"); } catch (IOException e) { System.out.println("An error occurred while creating the file."); } } }