SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
OS UNIT – 2 - Process Management
OS UNIT – 2 - Process ManagementOS UNIT – 2 - Process Management
OS UNIT – 2 - Process Management
 
javathreads
javathreadsjavathreads
javathreads
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
Exception handling
Exception handlingException handling
Exception handling
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 

Destaque

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
 

Destaque (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
 

Semelhante a Object Oriented Programming - File Input & Output

Semelhante a 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++
 

Mais de 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
 

Mais de 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
 

Último

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

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