C#中一些文件的操作

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";















  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值