Defiana Arnaldy, M.Si 0818 0296 4763 deff_arnaldy@yahoo.com File and Stream I/O Defiana Arnaldy, M.Si 0818 0296 4763 deff_arnaldy@yahoo.com.

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: File and Stream 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.
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.
Lecture Set 12 Sequential Files and Structures Part B – Reading and Writing Sequential Files.
Chapter 12 Working with Files CIS 3260 Introduction to Programming using C# Hiro Takeda.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Lector: Aliyev H.U. Lecture №5 Telecommunication network software design with.NET. Using streams for network programming TASHKENT UNIVERSITY OF INFORMATION.
 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
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
File Systems (1). Readings r Reading: Disks, disk scheduling (3.7 of textbook; “How Stuff Works”) r Reading: File System Implementation ( of textbook)
Files and Streams File Types, Using Streams, Manipulating Files SoftUni Team Technical Trainers Software University
11-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
File I/O What We’ll Cover –Visual Basic Techniques for Text Files –.NET Techniques for Text Files What We’ll Not Cover –Binary File I/O –XML File I/O.
Java Input/Output CSE301 University of Sunderland Harry Erwin, PhD Half Lecture.
Object Oriented Software Development 10. Persistent Storage.
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.
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.
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Input and Output 23: Input and Output
CSC 298 Streams and files.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
DEPARTMENT OF COMPUTER SCIENCE N.HARIKA. Contents Overview of I/O Streams Character Streams Byte Streams Using the Streams 2.
File Input and Output Chapter 14 Java Certification by:Brian Spinnato.
Ajay Tripathi Input Output. Ajay Tripathi Input/output (IO) refers to the operations for reading and writing data to streams and files. In the.NET Framework,
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 11 Data Files.
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.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
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 Streams Lec Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Chapter 6: Creating Windows–based Applications 1 Microsoft® Visual C# 2008.
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.
Ch14 Files and Streams OBJECTIVES
Input and Output 23: Input and Output
Reading & writing to files
University of Central Florida COP 3330 Object Oriented Programming
C# Programming: From Problem Analysis to Program Design
IS444: Modern tools for applications development
Files.
18 Files and Streams.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
IS444: Modern tools for applications development
I/O Basics.
File Types, Using Streams, Manipulating Files
Files and Streams.
Chapter 3 The .NET Framework Class Library (FCL)
Chapter 13: File Input and Output
Files and Streams Lect3 CT1411.
File Input/Output (I/O)
Operation System Program 4
Topics Introduction to File Input and Output
Files & Streams.
Cmdlets “Command-lets”
Files and Streams Lect10 GC201 12/1/2015.
CIS16 Application Development and Programming using Visual Basic.net
I/O and Applet from Chapter 12
Files and Streams.
Topics Introduction to File Input and Output
Chapter 11 Saving Data and Objects In Files
Presentation transcript:

Defiana Arnaldy, M.Si 0818 0296 4763 deff_arnaldy@yahoo.com File and Stream I/O Defiana Arnaldy, M.Si 0818 0296 4763 deff_arnaldy@yahoo.com

Overview Files and Directories Streams Readers and Writers Asynchronous I/O Operations Compression Isolated Storage I/O and Security

Introduction File and stream I/O (input/output) refers to the transfer of data either to or from a storage medium In the .NET Framework, the System.IO namespaces contain: types that enable reading and writing, both synchronously and asynchronously, on data streams and files. types that perform compression and decompression on files, and types that enable communication through pipes and serial ports.

A file is an ordered and named collection of bytes that has persistent storage directory paths, disk storage, and file and directory names A stream is a sequence of bytes that you can use to read from and write to a backing store, which can be one of several storage mediums (for example, disks or memory)

Files and Directories You can use the types in the System.IO namespace to interact with files and directories. For example, you can get and set properties for files and directories, and retrieve collections of files and directories based on search criteria.

Here are some commonly used file and directory classes: File - provides static methods for creating, copying, deleting, moving, and opening files, and helps create a FileStream object. FileInfo - provides instance methods for creating, copying, deleting, moving, and opening files, and helps create a FileStream object. Directory - provides static methods for creating, moving, and enumerating through directories and subdirectories.

DirectoryInfo - provides instance methods for creating, moving, and enumerating through directories and subdirectories. Path - provides methods and properties for processing directory strings in a cross-platform manner. In addition to using these classes, Visual Basic users can use the methods and properties provided by the Microsoft.VisualBasic.FileIO.FileSystem class for file I/O.

Streams The abstract base class Stream supports reading and writing bytes. Stream adalah representasi abstrak dari aliran data yang berjalan dari sumber (input stream) ke tujuan (output stream). Contoh: Membaca dan menulis file di dan ke harddisk Membaca dan menulis teks ke console. Membaca dan menulis melalui network

I/O Streams Untuk membaca  program membuka stream pada sumber ( file, memory, socket) dan membaca informasi secara sekuensial. Untuk menulis  program mengirim informasi ke tujuan dengan cara membuka stream tujuan, selanjutnya menulis informasi secara sekuensial.

Stream Misal: numerical data, executable programs, dll Byte stream (8 bit) digunakan untuk byte, integer, dan simple data type yang lain. Misal: numerical data, executable programs, dll Character stream (16bit) digunakan untuk data tekstual (teks), mendukung unicode. Misal: text files

Byte Stream

Character Stream

Streams involve three fundamental operations: Reading - transferring data from a stream into a data structure, such as an array of bytes. Writing - transferring data to a stream from a data source. Seeking - querying and modifying the current position within a stream.

Depending on the underlying data source or repository, a stream might support only some of these capabilities. For example, The PipeStream class does not support seeking. The CanRead, CanWrite, and CanSeek properties of a stream specify the operations that the stream supports.

Here are some commonly used stream classes: FileStream – for reading and writing to a file. IsolatedStorageFileStream – for reading and writing to a file in isolated storage. MemoryStream – for reading and writing to memory as the backing store. BufferedStream – for improving performance of read and write operations.

NetworkStream – for reading and writing over network sockets. PipeStream – for reading and writing over anonymous and named pipes. CryptoStream – for linking data streams to cryptographic transformations For an example of working with streams asynchronously, see Asynchronous File I/O.

Readers and Writers The System.IO namespace also provides types for reading encoded characters from streams and writing them to streams. Typically, streams are designed for byte input and output. The reader and writer types handle the conversion of the encoded characters to and from bytes so the stream can complete the operation. Each reader and writer class is associated with a stream, which can be retrieved through the class's BaseStream property.

Digunakan untuk membaca dan menulis data tekstual. Lebih mudah daripada menggunakan InputStream dan OutputStream. Untuk mempercepat performance, gunakan fasilitas buffering dengan: BufferedReader.

Here are some commonly used reader and writer classes: BinaryReader and BinaryWriter – for reading and writing primitive data types as binary values. StreamReader and StreamWriter – for reading and writing characters by using an encoding value to convert the characters to and from bytes. StringReader and StringWriter – for reading and writing characters to and from strings. TextReader and TextWriter – serve as the abstract base classes for other readers and writers that read and write characters and strings, but not binary data.

Sequential File Processing Sequential file processing example Text boxes Allow users to enter values for each record to be saved to a sequential file Names of the text boxes txtStRegNo txtLength txtManufacturer txtYear txtCustPhoneNo Object-Oriented Application Development Using VB .NET

Sequential File Processing Sequential file processing example (continued) Buttons Save To File button Clicked to save the text box values to a sequential file List Records button Clicked to extract the data from the file and display the results in a multiline text box with a vertical scroll bar Exit button Closes the program Object-Oriented Application Development Using VB .NET

Sequential File Processing Object-Oriented Application Development Using VB .NET

General Format for StreamWriter and StreamReader The boat attribute file example Uses the following methods of the StreamWriter class Write WriteLine Close Uses the following methods of the StreamReader class Read ReadLine ReadToEnd Peek Object-Oriented Application Development Using VB .NET

General Format for StreamWriter and StreamReader Object-Oriented Application Development Using VB .NET

Asynchronous I/O Operations Reading or writing a large amount of data can be resource-intensive. You should perform these tasks asynchronously if your application needs to remain responsive to the user. With synchronous I/O operations, the UI thread is blocked until the resource-intensive operation has completed. Use asynchronous I/O operations when developing Windows Store apps to prevent creating the impression that your app has stopped working.

The asynchronous members contain Async in their names, such as the CopyToAsync, FlushAsync, ReadAsync, and WriteAsync methods. You use these methods with the async and await keywords.

Compression Compression refers to the process of reducing the size of a file for storage. Decompression is the process of extracting the contents of a compressed file so they are in a usable format. The System.IO.Compression namespace contains types for compressing and decompressing files and streams.

The following classes are frequently used when compressing and decompressing files and streams: ZipArchive – for creating and retrieving entries in the zip archive. ZipArchiveEntry – for representing a compressed file.

ZipFile – for creating, extracting, and opening a compressed package. ZipFileExtensions – for creating and extracting entries in a compressed package. DeflateStream – for compressing and decompressing streams using the Deflate algorithm. GZipStream – for compressing and decompressing streams in gzip data format.

Isolated Storage Isolated storage is a data storage mechanism that provides isolation and safety by defining standardized ways of associating code with saved data. The storage provides a virtual file system that is isolated by user, assembly, and ( optionally ) domain.

Isolated storage is particularly useful when your application does not have permission to access user files. You can save settings or files for your application in a manner that is controlled by the computer's security policy.

The following classes are frequently used when implementing isolated storage: IsolatedStorage – provides the base class for isolated storage implementations. IsolatedStorageFile – provides an isolated storage area that contains files and directories. IsolatedStorageFileStream - exposes a file within isolated storage.

I/O and Security When you use the classes in the System.IO namespace, you must follow operating system security requirements such as access control lists (ACLs) to control access to files and directories. This requirement is in addition to any FileIOPermission requirements. You can manage ACLs programmatically.

A security check is performed only when the stream is constructed. Default security policies prevent Internet or intranet applications from accessing files on the user’s computer. Therefore, do not use the I/O classes that require a path to a physical file when writing code that will be downloaded over the Internet or intranet. A security check is performed only when the stream is constructed. Therefore, do not open a stream and then pass it to less-trusted code or application domains.

Referensi http://msdn.microsoft.com/en-us/library/k3352a4t.aspx

Sekian Terima Kasih