FileOutputStream & FileInputStream
Duration: 9 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- Prelims: General Knowledge: Physics Chemistry Biology History Geography Polity Indian Economy Static General Knowledge GK- Current Affairs Environment
- Prelims: General English: Vocabulary Noun Pronoun Adjectives Preposition Articles Direct and Indirect Speech Tenses Conjunction Subject Verb Agreement (Verb Noun Agreement) Modals Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing) Sentence Correction (Error Correction) Sentence Completion (Fill in the blanks) Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions) Cloze Test (Cloze Passage) Verbal Analogy (Word Based Analogy) Sentence Construction Adverb Verb
- Prelims: Quantitative Aptitude: Percentage Ratio and Proportion (Ratios) HCF LCM Divisibility Rules Average Sequence and Series (Series) Number System Powers and Exponents (Surds and Indices) Algebra Profit and Loss Simple Interest and Compound Interest Time and Work Pipe and Cistern Speed Time and Distance Mixture and Alligation Mensuration and Geometry Age Problems Partnership Statistics Data Interpretation Arithmetic
- Prelims: General Agriculture: Agriculture in India and Tripura Natural Resource Management Fundamentals of Crop Production Horticulture Crop Improvement Crop Protection Social Science
- IT Mains: Operating System: Introduction to OS Process Management CPU Scheduling Process Synchronization Threads & Process Creation Deadlock Memory Management Virtual Memory Disc Scheduling File Management Distributed Systems
- IT Mains: Computer Networking: Introduction to CN DLL: Access Control DLL: Flow Control DLL: Error Control Data Link Layer - Ethernet Net Layer: IPv4 & Proto Net Layer: IP Addressing Net Layer:Routing Protocol Transport Layer Services TL: Congestion & UDP Application Layer Hardware Basics Network Security
- IT Mains: DBMS: Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) Decomposition Properties & 4NF Relational Algebra SQL Relational Calculus Transaction Management Concurrency Control Database Recovery Big Data Systems Database Security & Authorization Enhanced Data Models NoSQL
- IT Mains: Software Engineering: Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management
- IT Mains: Data Structures & Algorithms: Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing Algorithm Analysis Time Complexity Analysis Sorting Algorithms
- IT Mains: OOPS with C++ & Java: C Fundamentals OOPS with C++ Java Fundamentals Array, String, IO & References OOPS with Java Generic & Collections Multithreading File Handling & I/O
- IT Mains: Python: Introduction to Python Tokens, Variables, Data Types, I/O Operators & Expressions Control Flow & Looping Collections & Strings Functions & Modules
- IT Mains: Website Development: Website, Browser & Services Internet Fundamentals Web Design & Development Protocols & Services Web Publishing & Hosting Server Side & Security Emerging Technologies HTML Basics HTML5 CSS JavaScript-Basics .Net Programming PHP
- IT Mains: Mobile App Development: Mobile Computing Multimedia
- IT Mains: Linux / Windows Server Admin: Unix OS Linux OS
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This lecture introduces Java file I/O using FileOutputStream and FileInputStream from the java.io package. The instructor defines FileOutputStream as a class used to write bytes to a file, emphasizing its uses: writing binary data such as images and audio files, writing text after converting it into bytes using getBytes(), and creating a file if it does not exist. A worked example in WriteFile.java demonstrates opening "a.txt" with a try-with-resources block, writing the string "Hello" converted to bytes via fos.write("Hello".getBytes()), and printing a success message. The output panel confirms "Data written successfully," and the file content shows "Hello." Red annotations underline key terms like "bytes" and circle fos.write, Hello, and the catch block to guide attention. The lecture then transitions to appending data: using the append-mode constructor of FileOutputStream allows adding new data at the end of an existing file without overwriting its old content. Finally, FileInputStream is introduced as a class in java.io used to read bytes from a file. A ReadFile.java example opens "a.txt" and reads it in a loop while ((i = fis.read()) != -1), casting each byte to char with (char) i and printing it. The console output displays "Hello," matching the file content. Red marks circle -1, fis.read(), and the (char) cast to highlight the end-of-file sentinel and byte-to-character conversion. The progression moves from writing bytes, to appending, to reading bytes back, forming a complete file I/O cycle.
Chapters
0:00 – 2:00 00:00-02:00
The slide titled "FileOutputStream" defines it as a class in the java.io package used to write bytes to a file, with three Uses bullets: writing binary data such as images and audio files, writing text after converting it into bytes, and creating a file if it does not exist. The WriteFile.java editor shows import java.io.*;, class writeFile, a try block with FileOutputStream fos = new FileOutputStream("a.txt"); and fos.write("Hello".getBytes());, plus a success print statement. The Output panel displays "Data written successfully," and the Content of a.txt panel shows line 1 reading "Hello." Red arrows emphasize the word "bytes" in the definition, and the instructor points to the catch block for exception handling.
2:00 – 5:00 02:00-05:00
The instructor continues annotating the FileOutputStream slide, underlining the definition line in red and drawing an arrow from "bytes." The Uses list remains visible, with one frame circling the second bullet in red. In WriteFile.java, line 10 reads fos.write("Hello".getBytes());, where the instructor circles "fos.write" and "Hello" in red. Red checkmarks are added beside the output text, the println success line, and the "Hello" file content to mark completed steps. The lecture then transitions to appending: to add new data at the end of an existing file without overwriting its old content, use the append-mode constructor. This introduces the concept that FileOutputStream can be configured to append rather than overwrite, preserving prior file content.
5:00 – 8:53 05:00-08:53
The slide titled "FileInputStream" lists the bullet "FileInputStream is a class in the java.io package used to read bytes from a file." The ReadFile.java editor shows a try block with new FileInputStream("a.txt") and a loop while ((i = fis.read()) != -1) printing (char) i. The right panels display Output (Console) text "Hello" and Content of a.txt row 1 "Hello." Red handwritten marks circle -1, fis.read(), and the (char) cast, with a note "char" near the class line. This demonstrates reading bytes one at a time until the end-of-file sentinel -1 is reached, converting each byte to a character for display. The example completes the file I/O cycle by reading back the data previously written with FileOutputStream.
The lecture builds a coherent file I/O workflow in Java. It begins by establishing FileOutputStream as the mechanism for writing bytes to a file, clarifying that text must be converted to bytes via getBytes() and that the class can create a missing file. The worked example in WriteFile.java ties definition to practice: opening "a.txt," writing "Hello" as bytes, and confirming success through console output and file content. Annotations such as red arrows on "bytes," circles around fos.write and Hello, and checkmarks beside output lines serve as visual cues to reinforce key steps. The transition to the append-mode constructor addresses a common pitfall: by default, FileOutputStream overwrites existing content, but append mode preserves it. The final section mirrors the writing process with FileInputStream, showing how to read bytes in a loop until -1 signals end of file and cast each byte to char for readable output. The consistent use of "a.txt" as the test file across both examples creates a clear before-and-after demonstration. For exam revision, students should remember: FileOutputStream writes bytes (use getBytes() for strings), can create files, and supports append mode; FileInputStream reads bytes in a loop checking for -1, with (char) casting to display text. The symmetry between writing and reading reinforces that file I/O in java.io operates at the byte level.

