SlideShare a Scribd company logo
Lecture 21Lecture 21
Version 1.0Version 1.0
Introduction to FileIntroduction to File
I/OI/O
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Different operations on filesDifferent operations on files
1.1. Creation of a new fileCreation of a new file
2.2. Opening an existing fileOpening an existing file
3.3. Reading from a fileReading from a file
4.4. Writing to a fileWriting to a file
5.5. Moving to a specific location in a file (seeking)Moving to a specific location in a file (seeking)
6.6. Closing a fileClosing a file
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Various file concepts from oneVarious file concepts from one
programprogram
 Now, we will see various concepts on files fromNow, we will see various concepts on files from
just one program.just one program.
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Error opening file??Error opening file??
 While opening the file in “r” mode, this mayWhile opening the file in “r” mode, this may
happen because the file being opened may nothappen because the file being opened may not
be present on the disk at allbe present on the disk at all
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
 Now we will write a program that countsNow we will write a program that counts
Character, newlines, blank spaces and tabs fromCharacter, newlines, blank spaces and tabs from
a filea file
12Rushdi Shams, Dept of CSE, KUET, Bangladesh

More Related Content

Viewers also liked

Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by ReferenceRushdi Shams
 
Lec 22. Files (Part II)
Lec 22. Files (Part II)Lec 22. Files (Part II)
Lec 22. Files (Part II)Rushdi Shams
 
Lec 17. String and Pointers
Lec 17. String and PointersLec 17. String and Pointers
Lec 17. String and PointersRushdi Shams
 
Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysRushdi Shams
 
L5 aggregate functions
L5  aggregate functionsL5  aggregate functions
L5 aggregate functionsRushdi Shams
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Rushdi Shams
 

Viewers also liked (8)

Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
 
Lec 22. Files (Part II)
Lec 22. Files (Part II)Lec 22. Files (Part II)
Lec 22. Files (Part II)
 
Lec 17. String and Pointers
Lec 17. String and PointersLec 17. String and Pointers
Lec 17. String and Pointers
 
Sql
SqlSql
Sql
 
Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
 
L5 aggregate functions
L5  aggregate functionsL5  aggregate functions
L5 aggregate functions
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
 

Similar to Lec 21. Files (Part I)

File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
Topic - File operation.pptx
Topic - File operation.pptxTopic - File operation.pptx
Topic - File operation.pptx
Adnan al-emran
 
Com ed 5 final
Com ed 5 finalCom ed 5 final
Com ed 5 final
bluejayjunior
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing OperationsRico
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing Operations
Don Bosco BSIT
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
armaansohail9356
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
ChereLemma2
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
VishuSaini22
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
HalaiHansaika
 
INT 1010 04-5.pdf
INT 1010 04-5.pdfINT 1010 04-5.pdf
INT 1010 04-5.pdf
Luis R Castellanos
 
Problem How do you copy a file Analyze the problem and con.pdf
Problem How do you copy a file Analyze the problem and con.pdfProblem How do you copy a file Analyze the problem and con.pdf
Problem How do you copy a file Analyze the problem and con.pdf
aadeshwarexports
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
271 instructional ppt+benchmarks
271 instructional ppt+benchmarks271 instructional ppt+benchmarks
271 instructional ppt+benchmarkskellymre
 
271 instructional pdf+benchmarks
271 instructional pdf+benchmarks271 instructional pdf+benchmarks
271 instructional pdf+benchmarkskellymre
 
UserGuideHDFS_FinalDocument
UserGuideHDFS_FinalDocumentUserGuideHDFS_FinalDocument
UserGuideHDFS_FinalDocumentAnna Ellis
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
MikialeTesfamariam
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
yndaravind
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdf
sulekha24
 

Similar to Lec 21. Files (Part I) (20)

File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Topic - File operation.pptx
Topic - File operation.pptxTopic - File operation.pptx
Topic - File operation.pptx
 
File handaling
File handalingFile handaling
File handaling
 
Com ed 5 final
Com ed 5 finalCom ed 5 final
Com ed 5 final
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing Operations
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing Operations
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
INT 1010 04-5.pdf
INT 1010 04-5.pdfINT 1010 04-5.pdf
INT 1010 04-5.pdf
 
Problem How do you copy a file Analyze the problem and con.pdf
Problem How do you copy a file Analyze the problem and con.pdfProblem How do you copy a file Analyze the problem and con.pdf
Problem How do you copy a file Analyze the problem and con.pdf
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
271 instructional ppt+benchmarks
271 instructional ppt+benchmarks271 instructional ppt+benchmarks
271 instructional ppt+benchmarks
 
271 instructional pdf+benchmarks
271 instructional pdf+benchmarks271 instructional pdf+benchmarks
271 instructional pdf+benchmarks
 
UserGuideHDFS_FinalDocument
UserGuideHDFS_FinalDocumentUserGuideHDFS_FinalDocument
UserGuideHDFS_FinalDocument
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdf
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
Rushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
Rushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
Rushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
Rushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process modelsRushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 

Recently uploaded

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 

Lec 21. Files (Part I)

  • 1. Lecture 21Lecture 21 Version 1.0Version 1.0 Introduction to FileIntroduction to File I/OI/O
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Different operations on filesDifferent operations on files 1.1. Creation of a new fileCreation of a new file 2.2. Opening an existing fileOpening an existing file 3.3. Reading from a fileReading from a file 4.4. Writing to a fileWriting to a file 5.5. Moving to a specific location in a file (seeking)Moving to a specific location in a file (seeking) 6.6. Closing a fileClosing a file
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Various file concepts from oneVarious file concepts from one programprogram  Now, we will see various concepts on files fromNow, we will see various concepts on files from just one program.just one program.
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Error opening file??Error opening file??  While opening the file in “r” mode, this mayWhile opening the file in “r” mode, this may happen because the file being opened may nothappen because the file being opened may not be present on the disk at allbe present on the disk at all
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh  Now we will write a program that countsNow we will write a program that counts Character, newlines, blank spaces and tabs fromCharacter, newlines, blank spaces and tabs from a filea file
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh