Understanding Input/Output (I/O) Classes Lesson 5.
-
Upload
vincent-nash -
Category
Documents
-
view
224 -
download
2
Transcript of Understanding Input/Output (I/O) Classes Lesson 5.
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)
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.
The Console Class
• Provides methods for reading data from and writing data to the console window.
Console Methods in Action
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.
Demonstration – Console Application
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.
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.
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.
Writing Text Files
Reading Text Files
Writing Binary Files
Reading Binary Files
XML
•XML (Extensible Markup Language) is a text-based format for representing structured data.
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.
Writing XML File
Reading XML File
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.
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