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
1 . Why does Java define both byte and character streams?
2 . Even though console input and output is text-based, why does Java still use byte
streams for this purpose?
3 . Show how to open a file for reading bytes.
4 . Show how to open a file for reading characters.
5 . Show how to open a file for random-access I/O.
6 . How can you convert a numeric string such as "123.23" into its binary equivalent?
7 . Write a program that copies a text file. In the process, have it convert all spaces into
hyphens. Use the byte stream file classes. Use the traditional approach to closing a
file by explicitly calling close( ) .
8 . Rewrite the program described in question 7 so that it uses the character stream
classes. This time, use the try -with-resources statement to automatically close the
file.
9 . What type of stream is System.in ?
Search WWH ::




Custom Search