.net core file I / O operations (a)

.net Directory class and provided to the user directories and files File class for operation, required prior to use references System.IO;

Directory class provides a series of static methods, it can be used to create, delete directories and other operations; File class provides create, delete, modify the file of the static method. Man of few words said, directly on the code:

string dirName = "test_dir";
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
string fileName = "data";
string fpath = dirName + '/' + fileName;
using (var s = File.OpenWrite(fpath))
{
s.WriteByte(100);
s.WriteByte(200);
}
Console.WriteLine("{0}文件创建时间:{1}",fpath,File.GetCreationTime(fpath));

The DateTime = new new Creattime the DateTime (2019,. 1,. 1,. 1,. 1,. 1);
File.SetCreationTime (fpath, Creattime);
Console.WriteLine ( "{0} After modifying the file creation time: {1}", fpath, File .GetCreationTime (fpath));

}

}

This code Directory.Exists (dirName) method is to verify the presence dirName directory exists returns True, and vice versa False;

File.OpenWrite (fpath) is to open a file or create a written fpath;

File.GetCreationTime (fpath) is to return fpath file creation time;

DateTime Creattime = new DateTime (2019, 1, 1, 1, 1, 1): instantiate a DateTime object to modify the file creation time;

 File.SetCreationTime (fpath, Creattime): available under the File class is used to modify the file creation time;

Code runs after the results:

 

Guess you like

Origin www.cnblogs.com/ymcc/p/12318623.html