IOException query
Posted: Sat May 17, 2008 4:40 am
I am coding an example from a text book
The start of the program is
The program compiles OK.
When I run it I get
Thanks
Alan
The start of the program is
Code: Select all
// Using a do-while to process a menu selection
class Menu
{
public static void main(String args[])
throws java.io.IOException
{
char choice;
do
{
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 < ' || choice > '5');
System.out.println("\n");When I run it I get
If I run the program from the command line it executes OK. I have used TextPad to code, compile and run about 30 other examples without any problem.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)
Thanks
Alan