Files and Streams Lec 13. 2 19.1 Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the.

Slides:



Advertisements
Similar presentations
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.
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
Managing data Resources: An information system provides users with timely, accurate, and relevant information. The information is stored in computer files.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Predecessor to the Database: Traditional File Processing Records are stored in files. Programs are customized to process the data.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
 2006 Pearson Education, Inc. All rights reserved File Processing.
17 File Processing. OBJECTIVES In this chapter you will learn:  To create, read, write and update files.  Sequential file processing.  Random-access.
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.
Bits and Data Storage. Basic Hardware Units of a Computer.
COMPUTING FOR BUSINESS AND ECONOMICS-III. Lecture no.6 COURSE INSTRUCTOR- Ms. Tehseen SEMESTER- Summer 2010.
UNIX Unbounded 5 th Edition Amir Afzal Chapter 1 First Things First.
 Memory Memory  Types of Memory Types of Memory  Memory Representation Memory Representation  Random Access Memory Random Access Memory  Read Only.
Files and Streams 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
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
1 Chapter 17 Disk Storage, Basic File Structures, and Hashing Chapter 18 Index Structures for Files.
Oleh Munawar Asikin. Principles of Information Systems, Seventh Edition 2  Database management system (DBMS): group of programs that manipulate database.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Operating Systems COMP 4850/CISG 5550 File Systems Files Dr. James Money.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
 2008 Pearson Education, Inc. All rights reserved File Processing.
 Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.  persistent data.  The smallest.
CS360 Windows Programming
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Data Storage © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 11 – File Processing Outline 11.1Introduction.
Chapter 12 Files (reference: Deitel ’ s chap 11) chap8.
 Pearson Education, Inc. All rights reserved Files and Streams.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
1 Exceptions Exception handling – Exception Indication of problem during execution – E.g., divide by zero – Chained exceptions Uses of exception handling.
Chapter 13.3: Databases Invitation to Computer Science, Java Version, Second Edition.
CSC 298 Streams and files.
Data Storage © 2007 Pearson Addison-Wesley. All rights reserved.
6.1 © 2007 by Prentice Hall Chapter 6 (Laudon & Laudon) Foundations of Business Intelligence: Databases and Information Management.
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
Hard Disk Geometry. Physical Sizes ( Also called Form Factor) Hard Drives currently come in 2 main sizes: 2.5” and 3.5” 2.5” Drives are for laptop computers.
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.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
CSE 1341 File I/O Exception Handling. Introduction to File Processing Data stored in variables and arrays is temporary. Main Memory Main Memory Secondary.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
File Processing.
17 File Processing.
TMF1414 Introduction to Programming
CSCI 3327 Visual Basic Chapter 11: Files and Streams
Files.
18 Files and Streams.
CSCI 161: Introduction to Programming
Lectures 12 Files & Streams Dr. Eng. Ibrahim El-Nahry.
How to work with files and data streams
Files and Streams.
Reading and Writing Files
MSIS 670: Object-Oriented Software Engineering
17 File Processing.
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.
Files and Streams Lect10 GC201 12/1/2015.
Fundamental of Programming (C)
Chapter 15 Files, Streams and Object Serialization
Files and Streams.
Presentation transcript:

Files and Streams Lec 13

Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.  Data maintained in files often is called persistent data.  Computers store files on secondary storage devices, such as magnetic disks, optical disks, flash memory and magnetic tapes.

Data Hierarchy  The smallest data item that computers support is called a bit (short for “binary digit”—a digit that can assume one of two values).  Digits, letters and special symbols are referred to as characters.

Data Hierarchy (Cont.)  Just as characters are composed of bits, fields are composed of characters. A field is a group of characters that conveys meaning.  Data items processed by computers form a data hierarchy (Fig. 19.1), in which data items become larger and more complex in structure.

Data Hierarchy (Cont.) Fig | Data hierarchy.

Data Hierarchy (Cont.)  Typically, a record is composed of several related fields.  A file is a group of related records.  To facilitate the retrieval of specific records from a file, at least one field in each record is chosen as a record key, which uniquely identifies a record.  A common file organization is called a sequential file, in which records typically are stored in order by a record-key field.  A group of related files often are stored in a database.  A collection of programs designed to create and manage databases is called a database management system (DBMS).

Files and Streams  C# views each file as a sequential stream of bytes (Fig. 19.2). Fig | C#’s view of an n-byte file. Each file ends either with an end-of-file marker or at a specific byte number that is recorded in a system-maintained administrative data structure. When a file is opened, an object is created and a stream is associated with the object.

Files and Streams (Cont.)  The System.IO namespace includes stream classes such as StreamReader, StreamWriter and FileStream for file input and output.  These stream classes inherit from abstract classes TextReader, TextWriter and Stream, respectively.  Abstract class Stream provides functionality for representing streams as bytes.  Classes FileStream, (from namespace System.IO ) inherit from class Stream.  Class FileStream can be used to write data to and read data from files.

9 Write using System.IO; class FileTest{ static void Main(string[] args){ FileStream wfile = new FileStream("D:\\Myname\\Test.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter stw = new StreamWriter(wfile); stw.WriteLine("Tabuk University"); stw.WriteLine("College of CS nad IT"); stw.WriteLine("Computer Science Department"); stw.Close(); }

10 Read class FileTest{ static void Main(string[] args){ FileStream rfile = new FileStream("D:\\Myname\\Test.txt", FileMode.Open, FileAccess.Read); StreamReader str = new StreamReader(rfile); string line1; while ((line1 = str.ReadLine()) != null) Console.WriteLine(line1); str.Close();} }