Anil Philip wrote:from Boyarsky page 814
The first two examples do not compile because they mix Reader/Writer classes with InputStream/OutputStream classes, respectively.
[...]
Was this an incorrect reason in the textbook?
It's a bit misleading. In general, most Reader/Writer classes and InputStream/OutputStream classes do not connect to each other directly. In the past, only InputStreamReader and OutputStreamWriter were the exceptions. Nowadays PrintWriter also has a variety of constructors that allow direct connections, too. But in general, most IO classes do not. So a more precise reason would be "The first two examples do not compile because they require specific constructors that do not exist." Or "The first two examples do not compile [b]because they mix Reader/Writer classes with InputStream/OutputStream classes, without using one of the classes that bridge these worlds. But their shortened explanation is still generally valid.
Classes that bridge these worlds include InputStreamReader, OutputStreamWriter, PrintWriter, Scanner, and probably others.
Note that once you're using PrintWriter, you don't need to provide a FileOutputStream or BufferedWriter, either. Those are provided for free if you use the appropriate constructor:
In the old days, anytime you used I/O stream you had to chain together two, three, or more different streams to do anything. Nowadays, you often need just one class, if it's a PrintWriter or Scanner or something from the Files class.