import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input the file pathname: "); String fname = in.next(); try { Scanner inFile = new Scanner(new File(fname)); int x = inFile.nextInt(); if (x < 0) throw new NegativeIntegerException("-ve number"); System.out.println("Data is: " + x); inFile.close(); } catch (FileNotFoundException e) { System.out.println("Cannot open ..."); } catch (InputMismatchException e) { System.out.println("Cannot read ..."); } catch (NegativeIntegerException e) { System.out.println(e.getMessage()); } in.close(); } }