IOException query

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
Alan-LB
Posts: 22
Joined: Sat Feb 02, 2008 4:29 am
Location: Junee, NSW, Australia

IOException query

Post by Alan-LB »

I am coding an example from a text book

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");
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)
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.

Thanks

Alan
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

I have used TextPad to code, compile and run about 30 other examples without any problem.
Did any of them read from System.in? My guess is: no.

As far as I know reading from System.in does not work if the java program is started from textpad (as stdin is still connected to Textpad, not to the java program).
User avatar
Alan-LB
Posts: 22
Joined: Sat Feb 02, 2008 4:29 am
Location: Junee, NSW, Australia

Post by Alan-LB »

You are right - none of the other programs read from System.in. This explains my problem - how can I get around it?

Thanks for your help

Alan
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Don't start your program from textpad, start it from command line
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Maybe that command line could be in a barch file that is started from a TextPad tool?
Hope this was helpful.............good luck,
Bob
User avatar
Alan-LB
Posts: 22
Joined: Sat Feb 02, 2008 4:29 am
Location: Junee, NSW, Australia

Post by Alan-LB »

It is not an important problem - I am just working through some examples in a text book. If the problem occurs again I will go straight to the command line.

Thanks for your help

Alan
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

use files

Post by Nicholas Jordan »

I got too many hangs trying to use System.in and that sort of thing. I tried doing everything from Files and got a major improvement in development time, mostly because of not being stuck staring at a hung box.
Post Reply