public static FileStream Open(string path,FileMode mode) |
private void OpenFile() { FileStream.TextFile=File.Open(@"c:\tempuploads\newFile.txt",FileMode.Append); byte [] Info = {(byte)''h'',(byte)''e'',(byte)''l'',(byte)''l'',(byte)''o''}; TextFile.Write(Info,0,Info.Length); TextFile.Close(); } |
public static FileStream Create(string path;) |
private void MakeFile() { FileStream NewText=File.Create(@"c:\tempuploads\newFile.txt"); NewText.Close(); } |
public static void Delete(string path); |
private void DeleteFile() { File.Delete(@"c:\tempuploads\newFile.txt"); } |
public static void Copy(string sourceFileName,string destFileName,bool overwrite); |
private void CopyFile() { File.Copy(@"c:\tempuploads\newFile.txt",@"c:\tempuploads\BackUp.txt",true); } |
public static void Move(string sourceFileName,string destFileName); |
private void MoveFile() { File.Move(@"c:\tempuploads\BackUp.txt",@"c:\BackUp.txt"); } |
public static void SetAttributes(string path,FileAttributes fileAttributes); |
private void SetFile() { File.SetAttributes(@"c:\tempuploads\newFile.txt", FileAttributes.ReadOnly|FileAttributes.Hidden); } |
public static bool Exists(string path); |
if(File.Exists(@"c:\tempuploads\newFile.txt")) //判断文件是否存在 { CopyFile(); //复制文件 DeleteFile(); //删除文件 MoveFile(); //移动文件 } else { MakeFile(); //生成文件 OpenFile(); //打开文件 SetFile(); //设置文件属性 } |
StreamReader TxtReader = new StreamReader(@"c:\tempuploads\newFile.txt",System.Text.Encoding.Default); string FileContent; FileContent = TxtReader.ReadEnd(); TxtReader.Close(); |
StreamWriter = new StreamWrite(@"c:\tempuploads\newFile.txt",System.Text.Encoding.Default); string FileContent; TxtWriter.Write(FileContent); TxtWriter.Close(); |
public static DirectoryInfo CreateDirectory(string path); |
private void MakeDirectory() { Directory.CreateDirectory(@"c:\tempuploads\NewDirectoty"); } |
private void SetDirectory() { DirectoryInfo NewDirInfo = new DirectoryInfo(@"c:\tempuploads\NewDirectoty"); NewDirInfo.Atttributes = FileAttributes.ReadOnly|FileAttributes.Hidden; } |
public static void Delete(string path,bool recursive); |
private void DeleteDirectory() { Directory.Delete(@"c:\tempuploads\BackUp",true); } |
public static void Move(string sourceDirName,string destDirName); |
private void MoveDirectory() { File.Move(@"c:\tempuploads\NewDirectory",@"c:\tempuploads\BackUp"); } |
public static string[] GetDirectories(string path;); |
private void GetDirectory() { string [] Directorys; Directorys = Directory. GetDirectories (@"c:\tempuploads"); } |
public static string[] GetFiles(string path;); |
private void GetFile() { string [] Files; Files = Directory. GetFiles (@"c:\tempuploads",); } |
public static bool Exists( string path; ); |
if(File.Exists(@"c:\tempuploads\NewDirectory")) //判断目录是否存在 { GetDirectory(); //获取子目录 GetFile(); //获取文件 MoveDirectory(); //移动目录 DeleteDirectory(); //删除目录 } else { MakeDirectory(); //生成目录 SetDirectory(); //设置目录属性 } |