Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.io.IOException: The handle is invalid

Status
Not open for further replies.

anticore

Technical User
Aug 26, 2001
32
0
0
HK
Hi,
I get the above (probably very simple and common) error when trying to run a function that reads input from the user using a InputStreamReader and a BufferedReader. After this it gives a bunch of function names with their variable types etc...
I have run this same function in a main class of its own and it executes fine; just does not work from a function call.
::Clearly I don't understand what the error indicates, except for the fact that it has thrown an exception!::
Any help appreciated
Regards, anticore
 
The method is:
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader(isr);
String s;
while((s = br.readLine()).length() != 0);

System.out.println ("");
return s;

All of this is inside a try{..}catch(..){..}

The error is along the lines of:
After catching the IOException it gives..
java.lang.String.BufferedReader(boolean)
java.lang.String.BufferedReader(...)
...
 
I tried running the following and it seemed okay (ctrl-Z to terminate console input stream)...




import java.io.*;

public class Hello {
public static void main(String [] args) {
try {
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader(isr);
String s;
while((s = br.readLine()).length() != 0);
} catch (Exception e) {
}
}
}


 
Thanks for the reply, however I can also get it to run successfully in a main class of its own but not when it is in a method of a class.

The complete error:
java.io.IOException: The handle is invalid.
java.lang.String java.io.BufferedReader.readLine(boolean)
java.lang.String java.io.BufferedReader.readLine()
java.lang.String boundary.B_Boundary.acceptChoice(java.lang.String)
void boundary.B_Boundary.runFirst()
void boundary.B_Boundary.<init>()
void control.C_Control.<init>(db_interface.D_DbInterface)
void control.C_Init.main(java.lang.String[])

The other classes listed are others in my app obviously.
Thanks for any help.
 
The problem is definitely with the line s = br.readLine();

I have tried:
while(true){
s = br.readLine();
if (s == null || s.length() == 0)
break;
}
and the exception is thrown at that line. It should be simple since readLine() waits for console input and just returns it as a string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top