Lab - Exp - 10 (Creating, Reading and Writing A File Using Input and Output Streams)
Lab - Exp - 10 (Creating, Reading and Writing A File Using Input and Output Streams)
CCS0023L
(Object Oriented Programming)
EXERCISE
10
Creating, Reading and Writing a File Using Input and
Output Streams
Section:
TX21
Doc Janice Abellana
Professor:
I. PROGRAM OUTCOME/S (PO) ADRESSED BY THE LABORATORY EXERCISE
a. Apply knowledge of computing appropriate to the discipline.
There are generally two types of streams, the character and byte streams. Let us just review the
basic difference between the two. Byte streams are file or device abstractions for binary data
while character streams are for Unicode characters.
The InputStream class is the abstract root class of all input byte streams whereas the
OutputStream class is the abstract root class of all output byte streams. For character streams, the
corresponding superclass of all classes are the Reader and the Writer class, respectively. Both
classes are abstract classes for reading and writing to character streams.
Streams are also categorized on whether they are used for reading or writing to streams.
Although it is already quite obvious, allow me to define these types of streams. You are allowed
to read from input streams but not write to them. On the other hand, you are allowed to write to
output streams but not read from them.
The InputStream class and the Reader class are the superclasses of all input streams.
The OutputStream class and the Writer class are the root classes of all output streams.
Input streams are also known as source streams since we get information from these
streams. Meanwhile, output streams are also called sink streams.
A node stream is a stream with the basic functionality of reading or writing from a specific
location such as a disk or from the network. Types of node streams include files, memory and
pipes. Filter streams, on the other hand, are layered onto node streams between threads or
processes to provide additional functionalities not found in the node stream by themselves.
Adding layers to a node stream is called stream chaining.
V. EXPERIMENTAL PROCEDURE:
1. Create a program that writes an Integer object to a stream and reads this object
from the stream.
2. Simple Encryption. Read from a file specified by the user and encrypt the content
of the file using a simple shifting technique. Also, ask the user to input the shift
size. Output the encrypted message to another file whose filename is also provided
by the user.
For example,
Shift size: 1
Message read from the file: Hello
Encrypted message: Ifmmp
1) Code:
Output:
2) Code:
Output:
VI. QUESTION AND ANSWER:
Note: The following rubrics/metrics will be used to grade students’ output in the lab
Exercise 10.