Java Reference
In-Depth Information
}
catch
catch
(
NumberFormatException ex
) {
System
.
err
.
println
(
"Not a valid number: "
+
line
);
}
catch
catch
(
IOException e
) {
System
.
err
.
println
(
"Unexpected IO ERROR: "
+
e
);
}
}
}
There are many other things you might want to do with lines of text read from a
Reader
. In
the demo program shown in this recipe, I just printed them. In the demo program in
Opening
StringTokenizer
(see
Breaking Strings Into Words
). You can also process the lines as you
read them; several methods for doing so are listed in
Scanning Input with StreamTokenizer
.
Reading from the Console or Controlling Terminal; Reading
Passwords Without Echoing
Problem
You want to read directly from the program's controlling terminal or console terminal.