0% found this document useful (0 votes)
13 views10 pages

Introduction To Streams in Computer Science

Uploaded by

charanfighter42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Introduction To Streams in Computer Science

Uploaded by

charanfighter42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Introduction to

Streams in
Computer
Science
Streams are sequences of bytes used for reading and writing data to
and from files. They are fundamental to input/output operations in
computer science.
Types of Streams: Text Streams and
Binary Streams
Text Streams Binary Streams

Text streams are designed for human-readable data, like Binary streams are for raw data, like images, audio, or
text files. Each character in a text stream is represented videos. Bytes in a binary stream can represent any value,
by a single byte. making them more flexible.
Input/Output
Operations on Text
Files
1 Reading Text Files 2
Writing to Text Files
Text files are read line-by- Data written to a text file is
line, with each line converted to strings and
interpreted as a string. stored line by line.

3 4 Error Handling
File Handling Functions
Specialized functions Functions are implemented
handle file operations like to check for errors during
opening, closing, reading, file operations, ensuring
writing, and seeking. data integrity.
Opening and Closing
Text Files
1 Opening
The file is opened and a connection is established
between the program and the file.

2 File Mode
The mode specifies how the file will be used, such as for
reading, writing, or appending.

3 Closing
The file connection is closed, releasing the resources
and saving any changes made to the file.
Reading and Writing Text Files
Reading Writing Error Handling
Data is read from the file, line by Data from memory is written to Error handling mechanisms
line, and stored in memory for the file, line by line, in the prevent data corruption and
processing. specified format. ensure successful file operations.
Input/Output
Operations on Binary
FilesReading Binary Files
Binary files are read byte by byte, providing access to
the raw data.

Writing to Binary Files


Data is written to binary files in raw byte format,
preserving the original data structure.

File Handling Functions


Specific functions are used to manage file operations in
binary mode, handling bytes and byte arrays.
Opening and Closing Binary Files
Opening Establishes a connection between the program and the
binary file.

File Mode Specifies how the file will be accessed, typically in "rb"
(read binary) or "wb" (write binary) mode.

Closing Releases the file resources and ensures data integrity


by saving any changes made.
Reading and Writing Binary Files

Reading Writing Error Handling


Bytes are read from the binary file, Data is written to the binary file in Error handling ensures data integrity
providing raw access to the data. byte format, preserving the original and prevents corruption during
structure and contents. read/write operations.
File Pointers and their Operations

File Pointer Seek Operations Tell Operations


A file pointer indicates the current Functions allow you to move the file Functions retrieve the current position
position within the file, allowing you pointer to a specific position within of the file pointer, providing
to read or write data at specific the file, enabling access to specific information about the data being
locations. data. accessed.
Conclusion and Key Takeaways
Streams are fundamental for handling input/output operations in computer science. Understanding different types of
streams, file handling techniques, and file pointer operations enables you to work efficiently with various types of data
and files.

You might also like