C# 第八次作业

这节课,我们学习了Stream的相关内容。

首先是Stream的大体介绍:.NET Framework provides Files and directories classes. These classes provide methods and properties for creating, naming, manipulating, and deleting files and directories on your disk, or Network. And it provides extensive support for serialization to create a stream of data(variables and objects). The .NET Framework provides buffered and unbuffered streams, and classes for asynchronous I/O.

关于file和directory:

1. Classes provided for file and directory manipulation.

2. The classes you need are in the System.IO namespace.

3. File class: Represents a file on disk.

4. Directory class: Represents a directory (Windows folder).

继承此类的对象可以跨越应用程序域边界被引用,甚至被远程引用。远程调用时, 将产生一个远程对象在本地的透明代理,通过此代理来进行远程调用。 使用代理交换消息来跨应用程序域边界进行通讯的对象的基类。

Working with Directories:

1. The Directory class exposes static methods for creating, moving, and exploring directories.

2. All the methods of the Directory class are static; therefore, you can call them all without having an instance of the class.

3. The DirectoryInfo class is a similar class, but one that has nothing but instance members (i.e.,no static members at all).

4. The FileSystemInfo class has a number of properties and methods that provide information about a file or directory.

Creating a DirectoryInfo:

1. Object To explore a directory hierarchy, you need to instantiate a DirectoryInfo object.

2. The DirectoryInfo class provides methods for getting not just the names of contained files and directories, but also FileInfo and DirectoryInfo objects, allowing you to dive in to the hierarchical structure, extracting subdirectories and exploring these recursively.

Working with Files:

1. The DirectoryInfo object can also return a collection of all the files in each subdirectory found.

2. The DirectoryInfo.GetFiles( ) method returns an array of FileInfo objects, each of which describes a file in that directory.

3. The FileInfo and File objects relate to one another, much as DirectoryInfo and Directory do.

4. Like the methods of Directory, all the File methods are static.

5. Like DirectoryInfo, all the methods of FileInfo are instance methods.

然后我试着运用了一下DirectoryInfo▼

 

其中

1. 从环境变量"SystemRoot"中得到特定字符串的值

string theDirectory = Environment.GetEnvironmentVariable("SystemRoot");

2.得到目录字符串theDirectory的对象

dir DirectoryInfo dir = new DirectoryInfo(theDirectory );

3.得到dir目录对象的文件集合

FileInfo[] filesInDir = dir.GetFiles();

4.得到dir对象的子目录集合

DirectoryInfo[] directories = dir.GetDirectories();

Principal methods of the Directory class:

CreateDirectory() :Creates all directories and subdirectories specified by its path parameter

GetCreationTime() :Returns and sets the time the specified directory was created

GetDirectories() :Gets named directories

GetLogicalDrives() :Returns the names of all the logical drives in the form <drive>:\

GetFiles() :Returns the names of files matching a pattern

GetParent() :Returns the parent directory for the specified path

Move() :Moves a directory and its contents to a specified path

Principal methods and properties of the DirectoryInfo class:

Attributes: Inherits from FileSystemInfo; gets or sets the creation time of the current file

CreationTime: Inherits from FileSystemInfo; gets or sets the creation time of the current file

Exists: Public property Boolean value, which is true if the directory exists

Extension: Public property inherited from FileSystemInfo; that is, the file extension

FullName: Public property inherited from FileSystemInfo; that is, the full path of the file or directory

LastAccessTime: Public property inherited from FileSystemInfo; gets or sets the last access time

LastWriteTime: Public property inherited from FileSystemInfo; gets or sets the time when the current file or directory was last written to

Name: Public property name of this instance of DirectoryInfo

Parent:  Public property parent directory of the specified directory

Root:  Public property root portion of the path

Create(): Public method that creates a directory

CreateSubdirectory(): Public method that creates a subdirectory on the specified path

Delete() : Public method that deletes a DirectoryInfo and its contents from the path

GetDirectories() : Public method that returns a DirectoryInfo array with subdirectories

GetFiles() :Public method that returns a list of files in the directory

GetFileSystemInfos() :Public method that retrieves an array of FileSystemInfo objects

MoveTo() :Public method that moves a DirectoryInfo and its contents to a new path

Refresh() :Public method inherited from FileSystemInfo; refreshes the state of the object

Principal public static methods of the File class:

AppendText() :Creates a StreamWriter that appends text to the specified file

Copy() : Copies an existing file to a new file

Create() :Creates a file in the specified path

CreateText() :Creates a StreamWriter that writes a new text file to the specified file

Delete() :Deletes the specified file

Exists() :Returns true if the specified file exists

GetAttributes(), SetAttributes() :Gets or sets the FileAttributes of the specified file

GetCreationTime(), SetCreationTime() :Returns or sets the creation date and time of the file

GetLastAccessTime(), SetLastAccessTime() :Returns or sets the last time the specified file was accessed

GetLastWriteTime(), SetLastWriteTime() :Returns or sets the last time the specified file was written to

Move() :Moves a file to a new location; can be used to rename a file

OpenRead() :Public static method that opens a FileStream on the file

OpenWrite() :Creates a read/write Stream on the specified path

Principal methods and properties of the FileInfo class:

Attributes() :Inherits from FileSystemInfo; gets or sets the attributes of the current file

CreationTime :Inherits from FileSystemInfo; gets or sets the creation time of the current file

Directory :Public property that gets an instance of the parent directory

Exists :Public property Boolean value that is true if the directory exists

Extension :Public property inherited from FileSystemInfo; that is, the file extension

FullName :Public property inherited from FileSystemInfo; that is, the full path of the file or directory

LastAccessTime :Public property inherited from FileSystemInfo; gets or sets the last access time

LastWriteTime :Public property inheritedfrom FileSystemInfo; gets or sets the time when the current file or directory was last written to

Length :Public property that gets the size of the current file

Name :Public property Name of this DirectoryInfo instance

AppendText() :Public method that creates a StreamWriter that appends text to a file

CopyTo() :Public method that copies an existing file to a new file

Create() :Public method that creates a new file

Delete() :Public method that permanently deletes a file

MoveTo() :Public method to move a file to a new location; can be used to rename a file

Open() :Public method that opens a file with various read/write and sharing privileges

OpenRead() :Public method that creates a read-only FileStream

OpenText() :Public method that creates a StreamReader that reads from an existing text file

OpenWrite() :Public method that creates a write-only FileStream

其实感觉这四部分大部分的都差不多……只有少数的几个是不一样的。

之后我们学习了关于改变文件读写数据一类的,因为还有一堆presentation没做怕玩脱了把电脑玩坏了就没做。

posted @ 2015-05-10 18:42  空翎  阅读(200)  评论(0编辑  收藏  举报