Use of file management in C # (Twelfth Day ),
It's time to sum up. Today, I have studied some application of file management in cloud and college and reviewed the Li's transformation I learned yesterday. Today, I will summarize the issues left over from yesterday and the knowledge I have learned today.
Issues left over yesterday
Lishi conversion (parent rotor class)
Example: Define the parent class People here, including the Name property subclass: Student contains the StadyNum property, an SsHi method.
People p = new Student (); // the action of the parent class is displayed.
Student p1 = p as Student; // The behavior action of the subclass is displayed.
P. Name = "Join"; // attributes in the parent class
P1.StadyNum = "01001"; // attributes in the subclass
P1.SsHi (); // call the subclass Method
Console. ReadKey ();
Theory and Practice:
File Management
Basic operations: Save, copy, move, and delete
Use of Path
String files = @ "D: \ yunhedata \ csharp.txt"; // If a string contains escape characters, add a @ symbol before the string.
Console. WriteLine (Path. GetFileName (files); // obtain the detailed name of the object (with the extension)
Console. WriteLine (Path. GetFileNameWithoutExtension (files); // only obtain the file name without the extension
Console. WriteLine (Path. GetExtension (files); // get the file extension
Console. WriteLine (Path. IsPathRooted (files); // check whether the root Path exists. A boolean value is returned.
String path1 = "c: \ temp ";
String path2 = "subdir \ file.txt ";
Console. WriteLine (Path. Combine (path1, path2); // merge Path
Console. WriteLine (Path. GetDirectoryName (files); // get the folder name
Console. WriteLine (Path. ChangeExtension (files); // change the extension
....
File Application
String file1 = @ "D: \ VS2013.iso ";
File. Greate (file1); // create a file1 File
File. Delete (file1); // Delete a file1 File
String sourcepath = @ "D: \ 11.docx ";
Tring destpath = @ "E: \ 11.docx ";
File. Copy (sourcepath, destpath, true); // Copy the sourcepath File to the destpath path. if it already exists, True indicates that it is overwritten.
File. CreateText (@ "E: \ 11.txt"); // create a text File named 11
File. OpenText (@ "E: \ 11.txt"); // open a text File
File. Move (@ "D: \ 1.rar", @" E: \ 1.rar"); // cut the File 1.rar on the D drive to the E drive.
String [] jGm = File. ReadAllLines (@ "F: \ Gm.txt"); // read all rows of a text document (assembled into an array)
String Gm = File. ReadAllText (@ "F: \ Gm.txt"); // read the text content (splice it into a string)
Returns a Boolean value to determine whether a file exists.
If (File. Exists(@ "F: \ jay.txt "))
{
Console. WriteLine ("file exists ");
}
Else
{
Console. WriteLine ("the file does not exist ");
}
Now, let's summarize it here today. We will learn file streams tomorrow. Come on!