# .NET Framework 文件 I/O 和文件系统基础知识 (Visual Basic)Basics of .NET Framework File I/O and the File System (Visual Basic)

System.IO 命名空间包含 FileDirectory 类，它们提供用于操作文件和目录的 .NET Framework 功能。The System.IO namespace contains the File and Directory classes, which provide the .NET Framework functionality that manipulates files and directories. 由于这些对象的方法是静态或共享成员，因此可直接使用，无需首先创建类的实例。Because the methods of these objects are static or shared members, you can use them directly without creating an instance of the class first. 与这些类相关联的是 FileInfoDirectoryInfo 类，使用 My 功能的用户将对它们很熟悉。Associated with these classes are the FileInfo and DirectoryInfo classes, which will be familiar to users of the My feature. 若要使用这些类，必须通过在受影响的代码开头包含 Imports 语句，完全限定名称或导入相应的命名空间。To use these classes, you must fully qualify the names or import the appropriate namespaces by including the Imports statement(s) at the beginning of the affected code. 有关详细信息，请参阅 Imports 语句（.NET 命名空间和类型）For more information, see Imports Statement (.NET Namespace and Type).

## 流的定义Definition of a Stream

.NET Framework 使用流来支持从文件中读取和写入文件。The .NET Framework uses streams to support reading from and writing to files. 可以将流视为一维连续数据集，具有开始和结束，并且其中的游标指示流中的当前位置。You can think of a stream as a one-dimensional set of contiguous data, which has a beginning and an end, and where the cursor indicates the current position in the stream.

## 流操作Stream Operations

• 读取Reading. 可以从流读取数据，将数据从流传输到数据结构，如字符串或字节数组。You can read from a stream, transferring data from the stream into a data structure, such as a string or an array of bytes.

• 编写Writing. 可以将数据写入流中，将数据从数据源传输到流。You can write to a stream, transferring data from a data source into the stream.

• 查找Seeking. 可以查询和修改流中的位置。You can query and modify your position in the stream.

To 请参阅See

## 文件访问权限和属性File Access and Attributes

FileAttributes 枚举可启用特定于文件的信息收集。The FileAttributes enumeration enables the gathering of file-specific information. FileAttributes 枚举返回文件的存储属性，如是否压缩、加密、隐藏、只读、是否为存档、目录、系统文件或临时文件。The FileAttributes enumeration returns the file's stored attributes, such as whether it is compressed, encrypted, hidden, read-only, an archive, a directory, a system file, or a temporary file.

To 请参阅See

To 请参阅See

## 文件事件File Events

FileSystemWatcher 组件允许监视系统上或任何你对其具有网络访问权限的计算机上的文件和目录所作的更改。The FileSystemWatcher component allows you to watch for changes in files and directories on your system or on any computer to which you have network access. 例如，如果修改了文件，可能想要向用户发送更改警报。For example, if a file is modified, you might want to send a user an alert that the change has taken place. 发生更改时，会引发一个或多个事件并将其存储在缓冲区中，然后移交给 FileSystemWatcher 组件进行处理。When changes occur, one or more events are raised, stored in a buffer, and handed to the FileSystemWatcher component for processing.