1.File.Exist检查文件是否存在
public static bool Exists(string path)
文件存在时,返回true,相反返回false。
2.读写文件
public static string ReadAllText(string path)
读取文件的所有行放入一个字符串中,然后关闭文件。
ppublic static string [] ReadAllLines(string path)
打开一个文本文件,将文件的所有行读入一个字符串数组,然后关闭文件。
public static void WriteAllText(string path,string contents)
创建一个新文件,写入内容然后关闭文件。文件已存在时,则覆盖该文件。
public static void WriteAllLines(string path,string [] contents)
public static void WriteAllLines(string path,string []contents,Encoding encoding)
创建一个新文件,向其中写入一个或者多个字符串,然后关闭文件
public static void AppendAllLines(string path,string [] contents)
public static void AppendAllText(string path,string []contents)
向已经存在的文本尾部追加内容,然后关闭文件。
3.创建文件
public static FileStream(string path)
4.将文本内容复制到另一个文本中
public static void Copy(string sourcepath,string destFileName)
不允许覆盖同名文件public static void Copy(string sourceFileName, string destFileName, bool overwrite)
overwrite为真时,可以覆盖文件,否则不能覆盖文件。
5.为文件加解密
public static void Decrypt(string path)
public static void Encrypt(string path)
6.删除文件
public static void Delete(string path)
7.文件的移动
public static void Move(string sourceFileName, string destFileName)
8.设置文件的创建时间
public static void SetCreationTime(string path, DateTime creationTime)
public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
9.Filter的使用
openFileDialog.Filter="Text files(*.txt)|*.txt";
openFileDialog.FIlter="Text files(*.txt)|*.txt|All files(*.*)|*.*";
openFileDialog.Filter= "图片|*.jpg;*.png;*.gif;*.jpeg;*.bmp";