I need help I'm trying to close the reader and It wil not let me.
Can some one tell me why and possible show me.
Expand|Select|Wrap|Line Numbers
- public static void main(String[] args) throws Exception {
- Scanner kbd = new Scanner(System.in);
- int choice;
- System.out.println("Make a Section: ");
- System.out.println("1. Read Text File ");
- System.out.println("2. Copy Text File ");
- System.out.println("3. Exit ");
- System.out.print("\nPlease press Enter afer each response");
- System.out.println("Enter your choose please: ");
- choice = kbd.nextInt();
- kbd.nextLine();
- if (choice == 1) { // if 1 is select go to makePerson
- String reader;
- String name = null;
- kbd = new Scanner (new File(name));
- try{
- System.out.print( "Enter the filename you want to open " );
- name = kbd.nextLine();
- while (kbd.hasNext())
- {
- reader = kbd.nextLine();
- System.out.println ( reader);
- System.out.println();
- }
- }finally{
- if (name !=null){
- name.close();
- }
- }
- }
sandyw