Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: File and Stream Tujuan Instruksional Khusus: Mahasiswa dapat.

Slides:



Advertisements
Similar presentations
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Pemrograman VisualMinggu …6… Page 1 MINGGU Ke Enam Pemrograman Visual Pokok Bahasan: Module, Class & Methods Tujuan Instruksional Khusus: Mahasiswa dapat.
Pemrograman VisualMinggu …2… Page 1 MINGGU Ke Dua Pemrograman Visual Pokok Bahasan: Console Application Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat.
Pemrograman VisualMinggu …7… Page 1 MINGGU Ke Tujuh Pemrograman Visual Pokok Bahasan: Arrays Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Pemrograman VisualMinggu …3… Page 1 MINGGU Ke Tiga Pemrograman Visual Pokok Bahasan: Class, Objects, Methods and Instance Variable Tujuan Instruksional.
Pemrograman VisualMinggu …8… Page 1 MINGGU Ke Delapan Pemrograman Visual Pokok Bahasan: Graphical User Interface Tujuan Instruksional Khusus: Mahasiswa.
Pemrograman VisualMinggu …4… Page 1 MINGGU Ke Empat Pemrograman Visual Pokok Bahasan: Control Statement I Tujuan Instruksional Khusus: Mahasiswa dapat.
C# - Files and Streams Outline Files and Streams Classes File and Directory Creating a Sequential-Access File Reading Data from a Sequential-Access.
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Chapter 9: Sequential Access Files and Printing
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
File Systems Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files.
ASP.NET Programming with C# and SQL Server First Edition
Creating Sequential-Access File  Serializable attribute indicates to the compiler that objects of a class can be serialized– written to or read from a.
Sequential-access file Create, read and write an object into a sequential-access file Serialize and deserialize the object to write and read from a data.
C# Programming: From Problem Analysis to Program Design1 Working with Files C# Programming: From Problem Analysis to Program Design 3 rd Edition 13.
File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Understanding Input/Output (I/O) Classes Lesson 5.
Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
1 Binary Files ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: Exception Handling Tujuan Instruksional Khusus: Mahasiswa dapat.
Visual C Sharp – File I/O - 1 Variables and arrays only temporary - lost when a program terminates Files used for long term storage (Data bases considered.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Pemrograman VisualMinggu …10… Page 1 MINGGU Ke Sepuluh Pemrograman Visual Pokok Bahasan: ADO.NET II Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
CIS 270—Application Development II Chapter 14—Files and Streams.
 2006 Pearson Education, Inc. All rights reserved Files and Streams.
1 14/10/58Dr.Mud-Armeen Munlin 1 Files and Streams ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
Tutorial 9: Sequential Access Files and Printing1 Tutorial 9 Sequential Access Files and Printing.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Lecture 19 Serialization Richard Gesick. Serialization Sometimes it is easier to read or write entire objects than to read and write individual fields.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
The Professional Touch Programming Right from the Start with Visual Basic.NET 1/e 10.
 Pearson Education, Inc. All rights reserved Files and Streams.
Object Serialization. Sequential-access Text Files Sequential-access files store records In order by the record-key field Java imposes no structure on.
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
1 Displaying Dialog Boxes Kashef Mughal. 2 Midterm Stats Here we go  Average was  Low was 116  High was 184  Mid Quarter Grade - check any.
C# Programming: From Problem Analysis to Program Design
Files.
18 Files and Streams.
CSCI 3327 Visual Basic Chapter 11: Files and Streams
Files and Streams Lect3 CT1411.
Sequential Input and Output using Text Files
File Input/Output (I/O)
Topics Introduction to File Input and Output
Files & Streams.
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides.
Tutorial 9 Sequential Access Files and Printing
Files and Streams Lect10 GC201 12/1/2015.
Fundaments of Game Design
CIS16 Application Development and Programming using Visual Basic.net
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Topics Introduction to File Input and Output
Chapter 11 Saving Data and Objects In Files
Presentation transcript:

Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: File and Stream Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan dan mengaplikasikan File and Stream pada Visual Basic 2008 Referensi: Deitel Deitel, Visual Basic 2008 (2009), How to Program, Prentice Hall. Chapter 13

Pemrograman VisualMinggu …12… Page 2 Agenda Class File and Directory Creating a Sequential-Access text File Reading Data From a Sequential Access Text File Creating a Sequential-Access file using object serialization Reading and Deserializing Data from a Sequential Access Text File

Pemrograman VisualMinggu …12… Page 3 Class File and Directory Didalam Namespace System.IO terdapat dua buah class yang dapat kita gunakan untuk mengolah sebuah file dan direktori yaitu class System.IO.File dan System.IO.Directory. Class System I.O File dapat kita manfaatkan untuk melakukan beberapa operasi dasar terhadap sebuah file seperti menyalin file, menghapus file dan sebagainya

Pemrograman VisualMinggu …12… Page 4 File class shared methods AppendText –Return a streamwriter that appends text to an existing file or create a file if one does not exist. Copy –Copies a file to a new file. Create –Creates a file and returns its associated FileStream. Delete –Deletes the specified file. Exists –Return true if the specified file exists and false otherwise.

Pemrograman VisualMinggu …12… Page 5 File class shared methods (Continued …) GetCreationTime –Returns a DateTime object representing when the file was created. GetLastAccessTime –Returns a DateTime object representing when the file was last access. GetLastWriteTime –Returns a DateTime object representing when the file was last modified. Move –Moves the specified file to a specified location.

Pemrograman VisualMinggu …12… Page 6 File class shared methods (Continued …) Open –Returns a FileStream associated with the specified file and equipped with the specified read/write permissions. OpenRead –Returns a read-only FileStream associated with the specified file. OpenText –Returns a StreamReader associated with the specified file. OpenWrite –Returns a read/write FileStream associated with the specified file.

Pemrograman VisualMinggu …12… Page 7 Directory class shared methods CreateDirectory –Create a directory and returns its associated DirectoryInfo object. Delete –Deletes the specified directory. Exists –Returns true if the specified directory exists and false otherwise. GetDirectories –Returns a string array containing the names of the subdirectories in the specified directory. GetFiles –Returns a string array containing the names of the files in the specified directory.

Pemrograman VisualMinggu …12… Page 8 Directory class shared methods (Continued …) GetCreationTime –Returns a DateTime object representing when the directory was created. GetLastAccessTime –Returns a DateTime object representing when the directory was last accessed. GetLastWriteTime –Returns a DateTime object representing when items were last written to the directory. Move –Moves the specified directory to a specified location.

Pemrograman VisualMinggu …12… Page 9 Demonstrating Classes File and Directory See Figure 18.5

Pemrograman VisualMinggu …12… Page 10 Creating a Sequential-Access Text File Visual Basic Imposes no structure on files, so it does not recognize concepts like ‘record”. This means that you must structure files to meet the requirement of your applications. A SaveFileDialog is a modal dialog. The three-argument FileStream constructor receive a String containing the name of the file to open, a constant describing how to open the file and a constant describing the file permissions. A StreamWriter object can be constructed with a FileStream argument that specifies the file to which StreamWriter outputs text. Class StreamWriter belongs to the System.IO Namespace

Pemrograman VisualMinggu …12… Page 11 Demonstrating Sequential-Access Text File Class BankUIForm See Figure 18.7 Class Record See Figure 18.8 Using a Character Stream to Create an output File See Figure 18.9

Pemrograman VisualMinggu …12… Page 12 Reading Data from a Sequential- Access Text File Data is stored in files so that it can be retrieved for processing when it is needed. To retrieve data sequentially from a file, programs normally start from the beginning of the file, reading data consecutively until the desired data is found. It sometimes is necessary to process a file sequentially several times during the execution of a program. An OpenFileDialog allows a user to select files to open. Method ShowDialog displays the dialog. See Figure

Pemrograman VisualMinggu …12… Page 13 Creating a Sequential-Access File Using Object Serialization Classes that are marked with the serializable attribute indicate to the CLR that objects of the class can be serialized. Objects that we wish to write to or read from a stream must include this attribute in their class definitions or implement the Iserializable interface. In a serializable class, you must ensure that every instance variable of the class is also serializable. By default, all simple type variables are serializable. For Reference type variables, you must check the declaration of the class (any possibly its supperclasses) to ensure that the type is serializable. See Figure

Pemrograman VisualMinggu …12… Page 14 Reading and Deserializing Data from a Sequential-Access Text File Method Deserialize (of class BinaryFormatter) reads a serialized object from a stream and reforms the object in memory. Method Deserialize returns a reference of type object which must be cast to the appropriate type to manipulate the object. If an error occurs during deserialization, a SerializationException is thrown. See Figure

Pemrograman VisualMinggu …12… Page 15 Questions & Answers

Pemrograman VisualMinggu …12… Page 16 Thank You