import java.io.*; public class Solution { public static void main(String[] args) throws IOException { //1.program should read file names from the console BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String fileName = null; try { boolean exists = true; while (exists) { fileName = reader.readLine(); //2.create an input stream for each file FileInputStream readFile = new FileInputStream(fileName); File tempFile = new File(fileName); exists = tempFile.exists(); //3. if file does not exist,catch FileNotFoundException if (!exists) { throw new FileNotFoundException(); } readFile.close(); } } catch (FileNotFoundException e) { reader.close(); System.out.println(fileName); } } }