Io operation (1)

Source: Internet
Author: User

1. For the path class, you can see from the compiler that this class is a static tool class. Note that this class is a string operation and has nothing to do with files.

1) changeextension () method, Modify the file suffix (call this method. If the second parameter is set to "", the extension is removed ).

1 // note that c: \ A \ BB \ CCC \ DDD \ 1.txt is not a real physical path 2 string Spath = path. changeextension (@ "C: \ A \ BB \ CCC \ DDD \ 1.txt ","*. xls "); 3 console. writeline (Spath );

The running result is as follows:

 

2) Combine () method, Merge paths.

1             string s1 = @"c:\a\b";2             string s2 = "c.doc";3             string fullPath = Path.Combine(s1, s2);4             Console.WriteLine(fullPath);

The running result is as follows:

3) obtain the directory of the path

1 string Path = @ "C: \ drivers \ win \ audio \ SaiI \ cxhdaudioapi. DLL "; 2 console. writeline (path. getdirectoryname (PATH); // obtain the directory section 3 console. writeline (path. getfilename (PATH); // obtain the file name 4 console. writeline (path. getfilenamewithoutextension (PATH); // obtain the file name (do not extend) 5 console. writeline (path. getextension (PATH); // obtain the file extension 6 console. readkey ();

The running result is as follows:

4) getfullpath)

1            string fullPath = Path.GetFullPath("1.txt");2             Console.WriteLine(fullPath);

The running result is as follows:

5) read files (readalltext, large files are not applicable)

1             string Msg = File.ReadAllText("1.txt");2             Console.WriteLine(Msg);

The running result is as follows:

 

6) Get the temporary directory

1 Console. writeline (path. gettemppath (); // return to the Temporary Folder path of the system.

A temporary directory is used by many software. For example, you can directly open a compressed package (rather than decompress the package) with the decompressed software, and the files you see will be placed in the temporary folder.

Gettempfilename () gets a unique temporary file name. This method creates a 0-byte file in the temporary directory.

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.