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
a File by Name , I convert them to integer values using Integer.parseInt() (also see
Checking Whether a String Is a Valid Number ) or using a DecimalFormat (see Formatting
Numbers ) . You can interpret them as dates ( Chapter 6 ), or break them into words with a
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.
Search WWH ::




Custom Search