SlideShare a Scribd company logo
1 of 19
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)

Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Labels and buttons
Labels and buttonsLabels and buttons
Labels and buttons
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Interface
InterfaceInterface
Interface
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Command prompt presentation
Command prompt presentationCommand prompt presentation
Command prompt presentation
 
JAVA - Herança
JAVA - HerançaJAVA - Herança
JAVA - Herança
 
Shell programming
Shell programmingShell programming
Shell programming
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Linux Servers
Linux ServersLinux Servers
Linux Servers
 

Viewers also liked

Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - InheritanceDudy Ali
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationDudy Ali
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseJava CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseDudy Ali
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesObject Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesDudy Ali
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsDudy Ali
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDatabase Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDudy Ali
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVADudy Ali
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolInformation System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolDudy Ali
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolInformation System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolDudy Ali
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetInformation System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetDudy Ali
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananInformation System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananDudy Ali
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananInformation System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananDudy Ali
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanDiagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanRicky Kusriana Subagja
 
Information System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan KeamananInformation System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan KeamananDudy Ali
 
Information System Security - Serangan dan Pengawasan
Information System Security - Serangan dan PengawasanInformation System Security - Serangan dan Pengawasan
Information System Security - Serangan dan PengawasanDudy Ali
 
Perancangan (diagram softekz, dfd level 0,1,2)
Perancangan (diagram softekz, dfd level 0,1,2)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 - KriptografiInformation System Security - Kriptografi
Information System Security - KriptografiDudy Ali
 
Information System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan JaringanInformation System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan JaringanDudy Ali
 

Viewers also liked (19)

Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & Encapsulation
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseJava CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server Database
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesObject Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference Types
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & Destructors
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDatabase Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL Server
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolInformation System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses Kontrol
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolInformation System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses Kontrol
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetInformation System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan Ekstranet
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananInformation System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen Keamanan
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananInformation System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen Keamanan
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanDiagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi Penjualan
 
MIS BAB 10
MIS BAB 10MIS BAB 10
MIS BAB 10
 
Information System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan KeamananInformation System Security - Konsep dan Kebijakan Keamanan
Information System Security - Konsep dan Kebijakan Keamanan
 
Information System Security - Serangan dan Pengawasan
Information System Security - Serangan dan PengawasanInformation System Security - Serangan dan Pengawasan
Information System Security - Serangan dan Pengawasan
 
Perancangan (diagram softekz, dfd level 0,1,2)
Perancangan (diagram softekz, dfd level 0,1,2)Perancangan (diagram softekz, dfd level 0,1,2)
Perancangan (diagram softekz, dfd level 0,1,2)
 
Information System Security - Kriptografi
Information System Security - KriptografiInformation System Security - Kriptografi
Information System Security - Kriptografi
 
Information System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan JaringanInformation System Security - Keamanan Komunikasi dan Jaringan
Information System Security - Keamanan Komunikasi dan Jaringan
 

Similar to Object Oriented Programming - File Input & Output

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

Cs 1114 - lecture-29
Cs 1114 - lecture-29Cs 1114 - lecture-29
Cs 1114 - lecture-29
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Unit 5
Unit 5Unit 5
Unit 5
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
Savitch ch 06
Savitch ch 06Savitch ch 06
Savitch ch 06
 
Aae oop xp_12
Aae oop xp_12Aae oop xp_12
Aae oop xp_12
 
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docxStudent Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
 
Csc1100 lecture15 ch09
Csc1100 lecture15 ch09Csc1100 lecture15 ch09
Csc1100 lecture15 ch09
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
Data file handling
Data file handlingData file handling
Data file handling
 
File Handling - N K Upadhyay
File Handling - N K UpadhyayFile Handling - N K Upadhyay
File Handling - N K Upadhyay
 
File management
File managementFile management
File management
 
File management in C++
File management in C++File management in C++
File management in C++
 

More from Dudy Ali

Understanding COM+
Understanding COM+Understanding COM+
Understanding COM+Dudy Ali
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Dudy Ali
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NETDudy Ali
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2Dudy Ali
 
XML Schema Part 1
XML Schema Part 1XML Schema Part 1
XML Schema Part 1Dudy Ali
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML DocumentDudy Ali
 
Pengantar XML
Pengantar XMLPengantar XML
Pengantar XMLDudy Ali
 
Pengantar XML DOM
Pengantar XML DOMPengantar XML DOM
Pengantar XML DOMDudy Ali
 
Pengantar ADO.NET
Pengantar ADO.NETPengantar ADO.NET
Pengantar ADO.NETDudy Ali
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBCDudy Ali
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTDudy Ali
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanAlgorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanDudy Ali
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarAlgorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarDudy Ali
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebWeb Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebDudy Ali
 
Web Programming Syaria - PHP
Web Programming Syaria - PHPWeb Programming Syaria - PHP
Web Programming Syaria - PHPDudy Ali
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeSoftware Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeDudy Ali
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekSoftware Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekDudy Ali
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekSoftware Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekDudy Ali
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)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 SistemSystem Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan SistemDudy Ali
 

More from Dudy Ali (20)

Understanding COM+
Understanding COM+Understanding COM+
Understanding COM+
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Distributed Application Development (Introduction)
Distributed Application Development (Introduction)
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NET
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2
 
XML Schema Part 1
XML Schema Part 1XML Schema Part 1
XML Schema Part 1
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
Pengantar XML
Pengantar XMLPengantar XML
Pengantar XML
 
Pengantar XML DOM
Pengantar XML DOMPengantar XML DOM
Pengantar XML DOM
 
Pengantar ADO.NET
Pengantar ADO.NETPengantar ADO.NET
Pengantar ADO.NET
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanAlgorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma Pengurutan
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarAlgorithm & Data Structure - Pengantar
Algorithm & Data Structure - Pengantar
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebWeb Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman Web
 
Web Programming Syaria - PHP
Web Programming Syaria - PHPWeb Programming Syaria - PHP
Web Programming Syaria - PHP
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeSoftware Project Management - Project Management Knowledge
Software Project Management - Project Management Knowledge
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekSoftware Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen Proyek
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekSoftware Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen Proyek
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan SistemSystem Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

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 dudy.fathan@eng.ui.ac.id