Posts

Showing posts from March, 2022

java.io package -Jonathan Knudsen, Patrick Niemeyer

Image
  Input/Output Facilities : The class hierarchy of the  java.io  package. these classes are all subclasses of the basic  InputStream ,  OutputStream ,  Reader , and  Writer  classes All fundamental I/O in Java is based on  streams . A stream represents a flow of data, or a channel of communication with (at least conceptually) a  writer  at one end and a  reader  at the other. When you are working with terminal input and output, reading or writing files, or communicating through sockets in Java, you are using a stream of one type or another. So that you can see the forest without being distracted by the trees, we’ll start by summarizing the classes involved with the different types of streams: InputStream/OutputStream Abstract classes that define the basic functionality  for reading or writing an unstructured sequence of bytes.  All other  byte streams  in Java are built on top of the basic  InputSt...

Terminal I/O

  Terminal I/O The prototypical  example of an  InputStream  object is the “standard input” of a Java application. Like  stdin  in C or  cin  in C++, this object reads data from the program’s environment, which is usually a terminal window or a command pipe. The  java.lang.System   class, a general repository for system-related resources, provides a reference to standard input in the static variable  in .  System  also provides objects for standard output and standard error in the  out  and  err variables, respectively. The following example shows the correspondence: InputStream stdin = System.in; OutputStream stdout = System.out; OutputStream stderr = System.err; This example hides the fact that  System.out  and  System.err  aren’t really  OutputStream  objects, but more specialized and useful  PrintStream  objects. We’ll explain these later, but for now we can re...