1. Managing the file system
Typically, applications have the need to save data and retrieve data.
1.1 Using the Path class to access file paths
"Path Common method": http://www.cnblogs.com/tangge/archive/2012/10/30/2746458.html#a3
1.2 Accessing files using the file and FileInfo classes 1.2.1
123456789101112131415161718 |
static
void
Main(
string
[] args)
{
string
sourceFileName =
@"F:\a.txt"
;
//源文件
string
destFileName =
@"c:\a.txt"
;
//目标文件
//如果源文件不存在
if
(!File.Exists(sourceFileName))
{
File.Create(sourceFileName).Close();
}
//如果目标文件存在,先删除
if
(File.Exists(destFileName))
{
File.Delete(destFileName);
}
File.Copy(sourceFileName, destFileName);
File.Delete(sourceFileName);
}
|
Duplicate record
String sourcefilename = @ "F:\a.txt"; Source file String destfilename = @ "C:\a.txt";//target file StreamWriter SW = File.appendtext (destfilename); Sw. WriteLine (String. Format ("{0} copy complete", DateTime.Now)); Sw. Flush (); Sw. Close ();
1.2.2 FileInfo Class
Length
private static void Main (string[] args) { string path = @ "E:\ zhongtian it\ video \dvd-asp.net\dvd-Zhang Bo. Netc1001\io-Zhang Bo. Netc1001\1 Last Review _ homework explained. avi "; FileInfo fi = new FileInfo (path); Console.WriteLine ( String. Format ("This file is {0:#.00}m", fi.) Length/(1024x768 * 1024x768)); }
1.3 Accessing Directories 1.3.1 Directory classes using the directory and DirectoryInfo classes
string path = @ "F:\tt\aeg\www"; if (directory.exists (path)) { directory.delete (path); } else { directory.createdirectory (path); }
string path = @ "F:\tt\aeg"; GetFiles retrieving file list string[] aa= directory.getfiles (path); foreach (var a in aa) { Console.WriteLine (a); } Console.WriteLine ("------------"); GetDirectories Retrieving the Folder List foreach (var s in directory.getdirectories (path)) { Console.WriteLine (s); } Console.WriteLine ("------------"); GetDirectories retrieving the folder and file list foreach (var s in directory.getfilesystementries (path)) { Console.WriteLine (s); }
1.3.2 DirectoryInfo Class
1.4 Using the DriveInfo class to access the drive
Console.WriteLine ("Drive {0}, type {1},", Dr. Name,dr. DriveType); if (Dr. IsReady) //{ Console.WriteLine ("Free space is {0}", Dr. Availablefreespace); //}
Console.WriteLine ("Drive {0}, type {1},", Dr. Name, Dr. DriveType); if (Dr. IsReady)//device is ready { Console.WriteLine ("\ t available space is {0}g", Dr. availablefreespace/(1024*1024*1024)); 41G Console.WriteLine ("\ t partition format {0}\n", Dr. Driveformat); NTFS }
1.5 FileSystemWatcher Class
2. Using a byte stream
3. Managing Application Data
4. Efficient operation of strings
(GO). NET Io:path, File, FileInfo, Directory, DirectoryInfo, DriveInfo, FileSystemWatcher