Category Archive for: Input/output: Exploring java.io

Objectinput

Objectinput The Object Input interface extends the DataInput interface and, defines the methods shown. It supports object serialization. Note especially the readObject method. This is called to deserialize an object. All of these methods will throw an IOException on error conditions. ObjectinputStream The ObjectInputStream class extends the InputStream class and implements the, ObjectInput interface, ObjectInputStream is responsible for…

Read More →

Serializable

Serializable Only an object that implements the Serializable interface can be saved and restored by the serialization facilities. The Serializable interface defines’no members. It is simply used to indicate that a class may be serialized. If.a class is serializable, all of its subclasses are also serializable Externalizable The lava facilities for serialization and deserialization have been designed so…

Read More →

Improving wc( ) Using a streamtokenizer

Improving wc( ) Using a streamtokenizer An even better way to-look for patterns in an input stream is to use another of Java’s 1/0 classes: StreamTokenizer. Similar to StringTokenizer from Chapter 16, StreamTokenizer breaks up the InputStream into tokens that are delimited by sets of characters. It has this constructor: We use the eolIsSignificant() method to ensure that…

Read More →

PrintWriter

PrintWriter PrintWriter is essentially a character-oriented version of PrintStream. It provides the .formatted output methods print( ) and println( ). PrintWriter has four constructors. Iava’s PrintWriter objects support the print( ) and println( ) methods for all types including Object. It.an argument is not a simple type, the PrintWriter methods will call. the object’s toString( ) method and…

Read More →

BufferedWriter

BufferedWriter A BufferedWriter is a Writer that adds a flush( ) method that can be used to ensure that data buffers are physically written to the actual output stream. Using a BuffcredWritcr can increase performance by reducing the number of times data is actually physically written to the output stream. The first form creates a buffered stream using…

Read More →

CharArrayReader

CharArrayReader CharArrayWriter is an implementation of an input stream that uses a character array as the source. This class has two constructors, each of which requires a character array to provide the .data source: Here, array is the input source. The second constructor creates a Reader from a subset of your character array that begins with the character…

Read More →

Writer

Writer Writer is an abstract class that defines streaming character output. AIl of the methods in this class return a void value and throw an IOException in the case of-errors. Table 17-4 shows a synopsis of the methods in Writer. FileReader FileReader class creates a Reader that you can use to read the contents of a file.…

Read More →

RandomAccessFile

RandomAccessFile RandomAccessFile encapsulates a random-access file..It is not derived from Inputstream or OutputStream. Instead, it implements the interfaces Datainput and DataOutput, which define the basic I/O methods. It also supports positioning requests-that is, you can position the file pointer within the file. It has these two constructors: RandomAccessFile(File fileObj, String access) throws IOException RandomAccessFile(String Jilenil11re, String. access) throws IoException…

Read More →

SequenceinputStream

SequenceinputStream The  SequeNce inputStream class allows  to concatenate multiple Input Streams. The construction of.a SequenceinputStream is different from any. other InputStream. A Sequence inputStream COnstructor uses either a pair of InputStream spr an  enumeration of putStrln as its argument: Sequence InputStream(InputStream first, inputStream second) Sequence InputStream (Enumeration Streaminput) Operationally, the class fulfills read requests from the first InputStream…

Read More →

BufferedOutputStream

BufferedOutputStream  added flush( ) method that is used to ensure that data buffers are physically written to \ the actual output device. Since the point of a BufferedOutputStream is to improve performance’ by reducing the number of times the system actually writes data, you may need to call flush ) to cause any data that is in the…

Read More →

Back to Top