Understanding Input/Output (I/O) Classes Lesson 5.

20
Understanding Input/Output (I/O) Classes Lesson 5

Transcript of Understanding Input/Output (I/O) Classes Lesson 5.

Page 1: Understanding Input/Output (I/O) Classes Lesson 5.

Understanding Input/Output (I/O) Classes

Lesson 5

Page 2: Understanding Input/Output (I/O) Classes Lesson 5.

Objective Domain Matrix

Skills/Concepts MTA Exam Objectives

Understanding console I/O Understand Console I/O (4.2)

Understanding .NET File Classes Understand .NET File Classes (4.1)

Understanding XML Classes in the .NET Framework

Understand XML Classes in the .NET Framework (4.3)

Page 3: Understanding Input/Output (I/O) Classes Lesson 5.

Console Input/Output

• Console applications do not have a graphical user interface and use a text-mode console window to interact with the user.• Console applications read from standard input stream.• Console applications write to standard output stream.• Console applications can receive input via command-line parameters.

Page 4: Understanding Input/Output (I/O) Classes Lesson 5.

The Console Class

• Provides methods for reading data from and writing data to the console window.

Page 5: Understanding Input/Output (I/O) Classes Lesson 5.

Console Methods in Action

Page 6: Understanding Input/Output (I/O) Classes Lesson 5.

Command-line Arguments

• The command-line arguments are the values passed to the Main method from the operating system. • The Main method receives the command-line arguments as

a string array.

Page 7: Understanding Input/Output (I/O) Classes Lesson 5.

Demonstration – Console Application

Page 8: Understanding Input/Output (I/O) Classes Lesson 5.

Manipulating Disk Files and Directories

•The File manipulation (example: copy, move, delete) classes are part of the System.IO namespace•The File and the FileInfo classes manipulate

disk files.•The Directory and DirectoryInfo classes

manipulate directories and sub-directories.•The File and the Directory classes contains only

static methods. •The FileInfo and the DirectoryInfo classes

contain the instance methods.

Page 9: Understanding Input/Output (I/O) Classes Lesson 5.

File Input and Output

•The classes for file-based input and output are part of the System.IO namespace.•Text files are the data files that contain only

character-based data. •The StreamReader and the StreamWriter

classes manipulate text files.•Binary files store any type of data as a sequence of

bytes.•The BinaryReader and the BinaryWriter

classes manipulate binary files.

Page 10: Understanding Input/Output (I/O) Classes Lesson 5.

Text Files

•A text file is a disk file that stores only character-based data.•Character encoding describes the rules by which

each character is represented.•There are different encoding schemes available,

such as ASCIIEncoding, UTF8Encoding, and UnicodeEncoding.•By using UTF8Encoding and UnicodeEncoding, you

can represent characters from all the international languages.

Page 11: Understanding Input/Output (I/O) Classes Lesson 5.

Writing Text Files

Page 12: Understanding Input/Output (I/O) Classes Lesson 5.

Reading Text Files

Page 13: Understanding Input/Output (I/O) Classes Lesson 5.

Writing Binary Files

Page 14: Understanding Input/Output (I/O) Classes Lesson 5.

Reading Binary Files

Page 15: Understanding Input/Output (I/O) Classes Lesson 5.

XML

•XML (Extensible Markup Language) is a text-based format for representing structured data.

Page 16: Understanding Input/Output (I/O) Classes Lesson 5.

Working with XML

•The classes to work with XML data are organized in the System.Xml namespace.•The XmlReader and XmlWriter classes provide

methods to respectively read data from and write data to XML files.•The XmlReader and XmlWriter classes provide

a fast, non-cached, and forward-only way to read or write XML data.

Page 17: Understanding Input/Output (I/O) Classes Lesson 5.

Writing XML File

Page 18: Understanding Input/Output (I/O) Classes Lesson 5.

Reading XML File

Page 19: Understanding Input/Output (I/O) Classes Lesson 5.

XML Schema

•XML schema describes the structure of an XML document. •An XML document is considered valid only when it

conforms to its XML schema.•XML schema is particularly important when an XML

file is used to share data between two applications. Without XML schema, the applications won’t know how the data in an XML file is structured.

Page 20: Understanding Input/Output (I/O) Classes Lesson 5.

Recap

• Console Input/Ouput• The Console class• Console methods• Command-line arguments

• Manipulating disk files and directories• File input and output• Text files• Binary files

• XML• Reading and writing XML• XML Schema