<1>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Path类
{
class Program
{
static void Main(string[] args)
{
//File 文件类
//-------------------------判断文件是否存在Exists()---------------------
//确定指定的文件是否存在。如存在则返回true;否则返回false
Console.WriteLine(File.Exists(@"d:\news\wowo.txt"));
//-------------------------创建文件Create()---------------------
//创建文件
File.Create(@"d:\news\hello.txt");
//在D盘创建一个utf8.txt文件,这个文件是用于写入 UTF-8 编码的文本。
File.CreateText(@"d:\utf8.txt");
//-------------------------删除文件Delete()---------------------
//删除指定文件(即便指定路径的文件不存在,也不会抛异常)
File.Delete(@"d:\news\hello.txt");
//-------------------------复制文件Copy()---------------------
//将d盘下的news文件夹下的wo.txt文件,复制到e盘下,命名为no.txt,true表示允许覆盖同名的文件。如果e盘之前就存在b.txt,那就就将其覆盖
File.Copy(@"d:\news\wo.txt", @"e:\no.txt",true);
//-------------------------剪切文件Move()---------------------
//将d盘下的news文件夹下的no.txt文件,剪切到e盘下,并重新将它命名为wo.txt (前提是e盘下之前就有a文件夹,否则抛异常:未能找到路径中的某个部分。)
File.Move(@"d:\news\no.txt",@"e:\aa\wo.txt");
//-------------------------替换指定文件的内容Replace()---------------------
//使用其他文件的内容替换指定文件的内容,这一过程将删除原始文件,并创建被替换文件的备份。
//将D盘下的1.txt文件内容【替换】2.txt文件的内容(这样2.txt里面将保存1.txt的内容),然后将1.txt文件删除。
File.Replace(@"d:\1.txt", @"d:\2.txt", @"d:\wowo.txt"); //既然2.txt的内容被1.txt替换掉了,那么第三个参数就是2.txt文件内容的备份 }
}
}
}