Hi all,
I am trying to work out how to use the try and catch methods in Java. I am new if you havent guessed and I am wondering how I can change my code which searches for a particular user id which is inputted and when found it opens the file corresponding to the name. I am having trouble working out how when the person is not found it throws the file not found exception. I am hoping to sidestep this and loop the code back to the add customer section.

Thanks in advance

import java.io.*;
 import java.util.*;
   public class AddProperty {
    public static void main(String[] args)throws Exception {
      String check2 = "NEW";
      // this is a section creatd to implement in larger assignment
      Scanner addScan = new Scanner(System.in);
      System.out.println("Please Enter the Landlords ID Number?");
      System.out.println("If a new Landlord type   NEW ");
      String check = addScan.nextLine(); 
      check = check.toUpperCase();
      //possible to loop here if file not found 
      if (check.equals(check2)) {
         System.out.println("Taking you to the new landlord section");
         // Will be adding code when completed the lower section
         /* Search for landlord which will be loaded in the initial setup
          * I am looking to have the user write a code i.e. ll001
          * which is linked to its own file. This will then load the information 
          * to be edited or updated.
         {System.out.println("Starting search for Landlord");
         String line = ""; 
         ArrayList data = new ArrayList();
         try { 
            FileReader fr = new FileReader(check + ".txt"); 
            BufferedReader br = new BufferedReader(fr);
         while((line = br.readLine()) != null) { 
         catch(FileNotFoundException fN) 
      catch(IOException e) { 
8 Years
Discussion Span
Last Post by NormR1

having trouble working out how when the person is not found it throws the file not found exception.

Have you looked at the File exists() method?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.