C # File Operations

Source: Internet
Author: User

In. all input and output in the. NET Framework must use a stream. A stream is an abstract serialized device that stores data in a linear manner and can be accessed in the same way: one byte is accessed at a time.

This device can be a disk file, printer, memory location, and any other object that supports linear read/write.

When writing data to some external targets, you need to use the output stream, which can be physical disk files, network locations, printers, or other programs.

Common classes:

File ---- static class, which provides many static methods for moving, deleting, and copying files.

Dictionary ---- category class, which provides many static methods for moving, deleting, and copying directories.

Path ---- use a class to process the path name.

Fileinfo ---- indicates the logistics file on the disk. You can use this method to process the file. to read and write the file, you must create a stream object.

Dictionaryinfo ---- indicates the physical directory on the disk, which can be processed.

Filestream ----- indicates a file that can be written, read, or written asynchronously.

Streamreader ------ reads character data from the stream and can be created as the base class by using filestream.

Streamwriter ------ write character data to a stream. You can use filestream to create a base class.

Filesystemwatcher ----- monitors files and directories and provides events that can be captured by applications when these locations change.

?

  1. File and dictionary classes

    As a classification class, the file and dictionary classes provide many methods for processing file systems and files and directories. These are static methods that involve moving files, querying and updating attributes, and creating filestream objects.

    File:

    Copy () ----- copy the file to the specified location

    Create () ----- create a file at a specified location

    Delete () ---- delete an object

    Open () ----- return the filestream object in the specified path

    Move () ---- move the specified file to a new location. You can specify different names for the file in the new location.

    Common static methods of directory classes

    Createdirectory () ----- create a directory with a specified path

    Delete () ----- delete a specified directory and all files in it

    Getdirectories () ----- returns the array of directory objects in the directory before the current directory

    Getfiles () ----- returns the array of file objects in the current directory

    Move () ----- move the specified directory to a new location. You can specify a new name for the folder in the new location.

  2. Fileinfo class

    Unlike the file class, the fileinfo class has no static method and can only be used to instantiate objects. The fileinfo object indicates a file in a disk or network location,

C # File Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.