Java Reference
In-Depth Information
Using this code, if you enter the number
123
on the keyboard, then
i
will contain the value
123.
Technically, you can call a
next
method without first calling a
hasNext
method.
However, doing so is not usually a good idea. If a
next
method cannot find the type of
data it is looking for, it throws an
InputMismatchException
. For this reason, it is best to
first confirm that the desired type of data is available by calling a
hasNext
method before
calling its corresponding
next
method.
Chapter 10 Self Test
streams for this purpose?
hyphens. Use the byte stream file classes. Use the traditional approach to closing a
file by explicitly calling
close( )
.
classes. This time, use the
try
-with-resources statement to automatically close the
file.