SlideShare a Scribd company logo
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
File Input & Output 1
Q3M1
Dudy Fathan Ali, S.Kom (DFA)
2015
CEP - CCIT
Fakultas Teknik Universitas Indonesia
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
o The stream is a sequence of bytes travelling from a source to a
destination over a communication path.
o The two basic streams used are the input and output streams.
o Input stream is used for a read operation.
o Output stream is used for performing a write operation.
o The System.IO namespace includes various classes, which are
used to perform operations, such as file creation, file deletion,
and the read-write operations to files.
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Common Class of System.IO Namespace
The following table describes some commonly used classes in the System.IO namespace.
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
FileStream Class
Most file Input/Output (I/O) support in the .NET Framework is implemented in
the System.IO namespace. You can use the FileStream class in the
System.IO namespace to read from, to write, and to close files.
FileStream [ObjName] = new FileStream([FileName],
[FileMode], [FileAccess])
Code Structure:
FileStream fs = new FileStream(“MyFile.txt”,
FileMode.Open, FileAccess.Read);
Example:
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
StreamReader and StreamWriter Class
The Stream class is used to read from and to write data in the text files. If data
of a file is only text, then you can use the StreamReader class and the
StreamWriter class to accomplish the reading and writing tasks
StreamReader sr = new StreamReader([ObjFileStream])
Code Structure:
FileStream fs = new FileStream(“MyFile.txt”,
FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
Example:
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of input data with FileStream and StreamWriter
File
Input.txt
FileStream StreamWriter
Write Data to
Stream
Mengosongkan
memori
Pembacaan data bisa
dari input user atau
dari cara yang lain
Data di simpan ke
dalam file Input.txt
Buka
StreamWriter
Buka
FileStream
Read Data
From User
Close SW &
FS
Tutup
StreamWriter dan
FileStream
Flush
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of input data with FileStream and StreamWriter
Consider the following code:
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Latihan Mandiri
Diketahui nama dosen sebagai berikut :
Masukkan lah nama-nama tersebut kedalam satu file dengan nama datadosen.txt
dengan menggunakan FileStream.
Catatan:
Nama dosen harus dimasukkan berdasarkan inputan user (bukan nilai statis dari
variable)
Dudy Fathan Ali S.Kom
Fachran Nazarullah S.Kom
Tri Agus Riyadi S.Kom
Riza Muhammad Nurman S.Kom
Musawarman S.Kom
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of reading data with FileStream and StreamReader
File
Output.txt
FileStream
Tampilkan
Data
Next Data
Y
N
Close SR
Close FS
Tutup
StreamReader
Tutup
FileStream
(b) Buka
StreamReader
(a) Buka
FileStream
(a)  Membuka File
(b)  Memuat Isi File ke dalam object
sr !=
null
StreamReader
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of reading data with FileStream and StreamWriter
Consider the following code:
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of search data with FileStream and StreamReader
File
Output.txt
FileStream StreamReader
sr !=
null
Y
N
Close SR
Close FS
Tutup
StreamReader
Tutup
FileStream
Buka StreamReader
Buka
FileReader
Data Search
Data yang di
cari
Variabel dataUntuk menampung
hasil pencarian data
Hasil cari
simpan ke
variabel data
Y
a
Cetak data
Apakah text yang di cari ada,
Jika iya maka akan di simpan
ke variabel data
Untuk pengecekan, anda bisa
menggunakan Contains
aNext Data
Y
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of search data with FileStream and StreamWriter
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Latihan Mandiri
Anda ditugaskan untuk mencari nama lengkap dari orang yang bernama “Fachran”
dari file datadosen.txt yang berisi data sebagai berikut :
Tampilkan data yang dicari sehingga menghasilkan output sebagai berikut :
Catatan :
Parameter pencarian harus dari inputan user (bukan nilai statis dari variable)
Data yang dicari : Fachran Nazarullah S.Kom
Dudy Fathan Ali S.Kom
Fachran Nazarullah S.Kom
Tri Agus Riyadi S.Kom
Riza Muhammad Nurman S.Kom
Musawarman S.Kom
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Delimiter
o Delimiter = Pemisah
o Simbol bisa digunakan untuk delimiter (#, $, &, ~)
o Implementasinya menggunakan array
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Delimiter
o Penggunaan Delimiter :
o Contoh input data pelanggan:
o ID Pelanggan : 8934
o Nama Pelanggan : Joni Simanjuntak
o Jenis Kelamin : Pria
o Alamat : Jakarta
8934#Joni Simanjuntak#Pria#Jakarta
8934;Joni Simanjuntak;Pria;Jakarta
Memiliki delimiter
dengan simbol ‘#’
Memiliki delimiter
dengan simbol ‘;’
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Mengapa harus menggunakan delimiter?
Berikut data pelanggan
---------------------------------
ID Pelanggan : 8934
Nama Pelanggan : Joni Simanjuntak
Jenis Kelamin : Pria
Alamat : Jakarta
Terkadang developer membutuhkan tampilan seperti ini:
Dengan menggunakan
delimiter, developer dapat
lebih mudah memecah data
yang satu dengan yang lain.
8934#Joni Simanjuntak#Pria#Jakarta
array[0] = 8394 array[1] = Joni
Simanjuntak
array[2] = Pria array[3] =
Jakarta
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of input data with delimiter format.
Consider the following code:
File Input & Output
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Process of reading data with delimiter format.
Consider the following code:
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Thank You!
Dudy Fathan Ali S.Kom
dudy.fathan@eng.ui.ac.id

More Related Content

What's hot (20)

Software Configuration Management (SCM)
Software Configuration Management (SCM)
Er. Shiva K. Shrestha
 
Distributed Hash Table
Distributed Hash Table
ravindra.devagiri
 
Communication in Distributed Systems
Communication in Distributed Systems
Dilum Bandara
 
How Computer Viruses Work
How Computer Viruses Work
Cerise Anderson
 
Sql Injection attacks and prevention
Sql Injection attacks and prevention
helloanand
 
Operating system memory management
Operating system memory management
rprajat007
 
11 Computer Privacy
11 Computer Privacy
Saqib Raza
 
Operating Systems & Applications
Operating Systems & Applications
Maulen Bale
 
Computer virus
Computer virus
Shubham Kafle
 
Database Health Check
Database Health Check
PostgreSQL Experts, Inc.
 
File organization
File organization
RituBhargava7
 
Event handling
Event handling
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Sam Bowne
 
Chapter 14 - Protection
Chapter 14 - Protection
Wayne Jones Jnr
 
Distributed file system
Distributed file system
Anamika Singh
 
Role of system analyst
Role of system analyst
prachi90501
 
Structured Design
Structured Design
Ajeng Savitri
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
Saeed Siddik
 
Component Based Development
Component Based Development
Ben McCormick
 
Page replacement algorithms
Page replacement algorithms
sangrampatil81
 
Software Configuration Management (SCM)
Software Configuration Management (SCM)
Er. Shiva K. Shrestha
 
Communication in Distributed Systems
Communication in Distributed Systems
Dilum Bandara
 
How Computer Viruses Work
How Computer Viruses Work
Cerise Anderson
 
Sql Injection attacks and prevention
Sql Injection attacks and prevention
helloanand
 
Operating system memory management
Operating system memory management
rprajat007
 
11 Computer Privacy
11 Computer Privacy
Saqib Raza
 
Operating Systems & Applications
Operating Systems & Applications
Maulen Bale
 
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Sam Bowne
 
Distributed file system
Distributed file system
Anamika Singh
 
Role of system analyst
Role of system analyst
prachi90501
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
Saeed Siddik
 
Component Based Development
Component Based Development
Ben McCormick
 
Page replacement algorithms
Page replacement algorithms
sangrampatil81
 

Viewers also liked (19)

Object Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
Dudy Ali
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server Database
Dudy Ali
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference Types
Dudy Ali
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & Destructors
Dudy Ali
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
 
Network Socket Programming with JAVA
Network Socket Programming with JAVA
Dudy Ali
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses Kontrol
Dudy Ali
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan Ekstranet
Dudy Ali
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi Penjualan
Ricky Kusriana Subagja
 
MIS BAB 10
MIS BAB 10
Riza Nurman
 
Information System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan Keamanan
Dudy Ali
 
Information System Security - Serangan dan Pengawasan
Information System Security - Serangan dan Pengawasan
Dudy Ali
 
Perancangan (diagram softekz, dfd level 0,1,2)
Perancangan (diagram softekz, dfd level 0,1,2)
Joel Marobo
 
Information System Security - Kriptografi
Information System Security - Kriptografi
Dudy Ali
 
Information System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan Jaringan
Dudy Ali
 
Object Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
Dudy Ali
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server Database
Dudy Ali
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference Types
Dudy Ali
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & Destructors
Dudy Ali
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
 
Network Socket Programming with JAVA
Network Socket Programming with JAVA
Dudy Ali
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses Kontrol
Dudy Ali
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan Ekstranet
Dudy Ali
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi Penjualan
Ricky Kusriana Subagja
 
Information System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan Keamanan
Dudy Ali
 
Information System Security - Serangan dan Pengawasan
Information System Security - Serangan dan Pengawasan
Dudy Ali
 
Perancangan (diagram softekz, dfd level 0,1,2)
Perancangan (diagram softekz, dfd level 0,1,2)
Joel Marobo
 
Information System Security - Kriptografi
Information System Security - Kriptografi
Dudy Ali
 
Information System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan Jaringan
Dudy Ali
 
Ad

Similar to Object Oriented Programming - File Input & Output (20)

Cs 1114 - lecture-29
Cs 1114 - lecture-29
Zeeshan Sabir
 
Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Unit 5
Unit 5
S.S.B.T’s. College of Engineering & Technology
 
file handling final3333.pptx
file handling final3333.pptx
radhushri
 
Savitch ch 06
Savitch ch 06
Terry Yoast
 
Aae oop xp_12
Aae oop xp_12
Niit Care
 
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
florriezhamphrey3065
 
Csc1100 lecture15 ch09
Csc1100 lecture15 ch09
IIUM
 
Introduction to files management systems
Introduction to files management systems
araba8
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
study material
 
File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
Abdullah khawar
 
Input output files in java
Input output files in java
Kavitha713564
 
Savitch Ch 06
Savitch Ch 06
Terry Yoast
 
Savitch Ch 06
Savitch Ch 06
Terry Yoast
 
Chpater29 operation-on-file
Chpater29 operation-on-file
Deepak Singh
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
YOGESH SINGH
 
Data file handling
Data file handling
Prof. Dr. K. Adisesha
 
Cs 1114 - lecture-29
Cs 1114 - lecture-29
Zeeshan Sabir
 
Stream classes in C++
Stream classes in C++
Shyam Gupta
 
file handling final3333.pptx
file handling final3333.pptx
radhushri
 
Aae oop xp_12
Aae oop xp_12
Niit Care
 
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
florriezhamphrey3065
 
Csc1100 lecture15 ch09
Csc1100 lecture15 ch09
IIUM
 
Introduction to files management systems
Introduction to files management systems
araba8
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
study material
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
Abdullah khawar
 
Input output files in java
Input output files in java
Kavitha713564
 
Chpater29 operation-on-file
Chpater29 operation-on-file
Deepak Singh
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
YOGESH SINGH
 
Ad

More from Dudy Ali (20)

Understanding COM+
Understanding COM+
Dudy Ali
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)
Dudy Ali
 
Review Materi ASP.NET
Review Materi ASP.NET
Dudy Ali
 
XML Schema Part 2
XML Schema Part 2
Dudy Ali
 
XML Schema Part 1
XML Schema Part 1
Dudy Ali
 
Rendering XML Document
Rendering XML Document
Dudy Ali
 
Pengantar XML
Pengantar XML
Dudy Ali
 
Pengantar XML DOM
Pengantar XML DOM
Dudy Ali
 
Pengantar ADO.NET
Pengantar ADO.NET
Dudy Ali
 
Database Connectivity with JDBC
Database Connectivity with JDBC
Dudy Ali
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
Dudy Ali
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - Pengantar
Dudy Ali
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
 
Web Programming Syaria - PHP
Web Programming Syaria - PHP
Dudy Ali
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management Knowledge
Dudy Ali
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen Proyek
Dudy Ali
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)
Dudy Ali
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
Dudy Ali
 
Understanding COM+
Understanding COM+
Dudy Ali
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)
Dudy Ali
 
Review Materi ASP.NET
Review Materi ASP.NET
Dudy Ali
 
XML Schema Part 2
XML Schema Part 2
Dudy Ali
 
XML Schema Part 1
XML Schema Part 1
Dudy Ali
 
Rendering XML Document
Rendering XML Document
Dudy Ali
 
Pengantar XML
Pengantar XML
Dudy Ali
 
Pengantar XML DOM
Pengantar XML DOM
Dudy Ali
 
Pengantar ADO.NET
Pengantar ADO.NET
Dudy Ali
 
Database Connectivity with JDBC
Database Connectivity with JDBC
Dudy Ali
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
Dudy Ali
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - Pengantar
Dudy Ali
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
 
Web Programming Syaria - PHP
Web Programming Syaria - PHP
Dudy Ali
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management Knowledge
Dudy Ali
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen Proyek
Dudy Ali
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)
Dudy Ali
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
Dudy Ali
 

Recently uploaded (20)

FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 

Object Oriented Programming - File Input & Output

  • 1. Q3M1 – OOP C# Dudy Fathan Ali S.Kom File Input & Output 1 Q3M1 Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom o The stream is a sequence of bytes travelling from a source to a destination over a communication path. o The two basic streams used are the input and output streams. o Input stream is used for a read operation. o Output stream is used for performing a write operation. o The System.IO namespace includes various classes, which are used to perform operations, such as file creation, file deletion, and the read-write operations to files.
  • 3. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Common Class of System.IO Namespace The following table describes some commonly used classes in the System.IO namespace.
  • 4. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom FileStream Class Most file Input/Output (I/O) support in the .NET Framework is implemented in the System.IO namespace. You can use the FileStream class in the System.IO namespace to read from, to write, and to close files. FileStream [ObjName] = new FileStream([FileName], [FileMode], [FileAccess]) Code Structure: FileStream fs = new FileStream(“MyFile.txt”, FileMode.Open, FileAccess.Read); Example:
  • 5. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom StreamReader and StreamWriter Class The Stream class is used to read from and to write data in the text files. If data of a file is only text, then you can use the StreamReader class and the StreamWriter class to accomplish the reading and writing tasks StreamReader sr = new StreamReader([ObjFileStream]) Code Structure: FileStream fs = new FileStream(“MyFile.txt”, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); Example:
  • 6. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of input data with FileStream and StreamWriter File Input.txt FileStream StreamWriter Write Data to Stream Mengosongkan memori Pembacaan data bisa dari input user atau dari cara yang lain Data di simpan ke dalam file Input.txt Buka StreamWriter Buka FileStream Read Data From User Close SW & FS Tutup StreamWriter dan FileStream Flush
  • 7. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of input data with FileStream and StreamWriter Consider the following code:
  • 8. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Latihan Mandiri Diketahui nama dosen sebagai berikut : Masukkan lah nama-nama tersebut kedalam satu file dengan nama datadosen.txt dengan menggunakan FileStream. Catatan: Nama dosen harus dimasukkan berdasarkan inputan user (bukan nilai statis dari variable) Dudy Fathan Ali S.Kom Fachran Nazarullah S.Kom Tri Agus Riyadi S.Kom Riza Muhammad Nurman S.Kom Musawarman S.Kom
  • 9. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of reading data with FileStream and StreamReader File Output.txt FileStream Tampilkan Data Next Data Y N Close SR Close FS Tutup StreamReader Tutup FileStream (b) Buka StreamReader (a) Buka FileStream (a)  Membuka File (b)  Memuat Isi File ke dalam object sr != null StreamReader
  • 10. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of reading data with FileStream and StreamWriter Consider the following code:
  • 11. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of search data with FileStream and StreamReader File Output.txt FileStream StreamReader sr != null Y N Close SR Close FS Tutup StreamReader Tutup FileStream Buka StreamReader Buka FileReader Data Search Data yang di cari Variabel dataUntuk menampung hasil pencarian data Hasil cari simpan ke variabel data Y a Cetak data Apakah text yang di cari ada, Jika iya maka akan di simpan ke variabel data Untuk pengecekan, anda bisa menggunakan Contains aNext Data Y
  • 12. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of search data with FileStream and StreamWriter
  • 13. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Latihan Mandiri Anda ditugaskan untuk mencari nama lengkap dari orang yang bernama “Fachran” dari file datadosen.txt yang berisi data sebagai berikut : Tampilkan data yang dicari sehingga menghasilkan output sebagai berikut : Catatan : Parameter pencarian harus dari inputan user (bukan nilai statis dari variable) Data yang dicari : Fachran Nazarullah S.Kom Dudy Fathan Ali S.Kom Fachran Nazarullah S.Kom Tri Agus Riyadi S.Kom Riza Muhammad Nurman S.Kom Musawarman S.Kom
  • 14. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Delimiter o Delimiter = Pemisah o Simbol bisa digunakan untuk delimiter (#, $, &, ~) o Implementasinya menggunakan array
  • 15. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Delimiter o Penggunaan Delimiter : o Contoh input data pelanggan: o ID Pelanggan : 8934 o Nama Pelanggan : Joni Simanjuntak o Jenis Kelamin : Pria o Alamat : Jakarta 8934#Joni Simanjuntak#Pria#Jakarta 8934;Joni Simanjuntak;Pria;Jakarta Memiliki delimiter dengan simbol ‘#’ Memiliki delimiter dengan simbol ‘;’
  • 16. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Mengapa harus menggunakan delimiter? Berikut data pelanggan --------------------------------- ID Pelanggan : 8934 Nama Pelanggan : Joni Simanjuntak Jenis Kelamin : Pria Alamat : Jakarta Terkadang developer membutuhkan tampilan seperti ini: Dengan menggunakan delimiter, developer dapat lebih mudah memecah data yang satu dengan yang lain. 8934#Joni Simanjuntak#Pria#Jakarta array[0] = 8394 array[1] = Joni Simanjuntak array[2] = Pria array[3] = Jakarta
  • 17. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of input data with delimiter format. Consider the following code:
  • 18. File Input & Output Q3M1 – OOP C# Dudy Fathan Ali S.Kom Process of reading data with delimiter format. Consider the following code:
  • 19. Q3M1 – OOP C# Dudy Fathan Ali S.Kom Thank You! Dudy Fathan Ali S.Kom [email protected]