import java.util.*; import javax.swing.*; import java.io.*; public class Scanner1 { public static void main(String[] args) { FileInputStream myStream = null; boolean OK = false; while (!OK) { try { String s = JOptionPane.showInputDialog(null,"Enter file name"); myStream = new FileInputStream(s); OK = true; } catch (IOException e) { System.out.println("Bad File Name"); } } Scanner in = new Scanner(myStream); // As long as there is to be something new to be read from // the file, read a line, convert to upper case, then // print. while (in.hasNext()) { String line = in.nextLine(); System.out.println(line.toUpperCase()); } in.close(); } }