2 Replies Latest reply on May 17, 2008 4:36 AM by 807601

    IOException query

      I am coding an example from a text book

      The start of the program is
      //  Using a do-while to process a menu selection
      class Menu
           public static void main(String args[])
           throws java.io.IOException
                char choice;
                     System.out.println("Help on:");
                     System.out.println("   1.  if");
                     System.out.println("   2.  switch");
                     System.out.println("   3.  while");
                     System.out.println("   4.  do-while");
                     System.out.println("   5.  for\n");
                     System.out.println("Choose one: ");
                     choice = (char) System.in.read();
                } while(choice <  '1' || choice > '5');
      The program compiles OK.
      When I run it I get

      Help on:
      1. if
      2. switch
      3. while
      4. do-while
      5. for

      Choose one:
      Exception in thread "main" java.io.IOException: The handle is invalid
           at java.io.FileInputStream.readBytes(Native Method)
           at java.io.FileInputStream.read(FileInputStream.java:199)
           at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
           at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
           at Menu.main(Menu.java:20)

      Question 1: What does "The handle is invalid" mean?
      Question 2: Where can I find answers to questions like this for myself in future?


        • 1. Re: IOException query
          It works fine when I compile and run it - I added the last pair of } and corrected the typo that the forum formatting seemed to have introduced.

          Are you compiling and running the program from the command line?
          • 2. Re: IOException query
            I am using TextPad to enter the code - then Tools > Compile then Run. All the other 30 examples have run OK using this method.

            Yes - I checked running the program from the command line and it is OK!!

            I will ask the question in the TextPad forum.

            Thanks for your help