// Project: InputOutput // No modules defined. // Source code file: UseFileChooser // Open an output file with a FileChooser dialog. // Read names and write greetings as in the // WriteGreetings class. import java.io.*; import java.util.Scanner; import javax.swing.JFileChooser; public class UseFileChooser { public static void main(String[] args) throws FileNotFoundException { // Open file containing names with FileChooser dialog JFileChooser chooser = new JFileChooser( ); chooser.showOpenDialog(null); File fileObj = chooser.getSelectedFile( ); // Read names and write greetings, each in its own file. Scanner in = new Scanner(fileObj); while (in.hasNextLine( )) { String name = in.nextLine( ); String greeting = "Hello " + name + ", how are you?"; PrintWriter pw = new PrintWriter(name + ".txt"); pw.println(greeting); pw.close( ); } in.close( ); } }