IO操作


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
 1,判断文件夹与文件是否存在及创建
if (System.IO.Directory.Exists(Server.MapPath("file")) == false)//如果不存在就创建file文件夹
             {
                 System.IO.Directory.CreateDirectory(Server.MapPath("file"));
             }
System.IO.Directory.Delete(Server.MapPath("file"),true);//删除文件夹以及文件夹中的子目录,文件    

判断文件的存在
if (System.IO.File.Exist(Server.MapPath("~/Back/Data.xml"))
{
//存在文件
}  
else
{
    File.Create("c.txt");
}

2,写文件
StreamWriter sw = new StreamWriter(“c.txt”, false, code);
     sw.Write('as');
 sw.Flush();
读文件
 StreamReader sr = null;
 string str = "";
            try
            {
                sr = new StreamReader(temp, code);
                str = sr.ReadToEnd();   //   读取文件   
            }