C# 创建目录

C#创建目录
var strpatj = HttpRuntime.AppDomainAppPath;
if (!Directory.Exists(strpatj+"\\temp"))
Directory.CreateDirectory(strpatj + "\\temp");
C#在目录下创建文件
StreamReader sr = new StreamReader(filestrem, System.Text.Encoding.GetEncoding("gb2312")); //读取这个流
using (StreamWriter sw = new StreamWriter(strpatj + "\\temp\\" + "temp.csv"))
{
sw.Write(sr.ReadToEnd()); //读取后, sr无数据
}

//带编码方式写入
using (StreamWriter sw = new StreamWriter(strpatj + "\\temp\\" + "temp.csv", false, Encoding.GetEncoding("gb2312")))
{
sw.Write(sr0.ReadToEnd());
}



//在读取该文件,返回一个Stream.
StreamReader sr1 = new StreamReader(strpatj + "\\temp\\" + "temp.csv", System.Text.Encoding.GetEncoding("gb2312")); //读取这个流
filestrem =  sr1.BaseStream;


//未测试
using (FileStream fsw = new FileStream(strpatj + "\\temp\\" + "temp.csv", FileMode.Create, FileAccess.Write))  //打开文件,用于只写??
{
BinaryWriter bw = new BinaryWriter(fsw); //编写器指向这个文件流??
bw.Write(System.IO.File.ReadAllBytes(strpatj + "\\temp\\" + "temp.csv"));    //打开一个文件读取流信息,将其写入新文件??
System.IO.File.Delete(path + i.ToString() + "_" + filename);        //删除指定文件信息??
bw.Flush(); //清理缓冲区??
}

 

posted @ 2019-06-25 17:10  enych  阅读(11409)  评论(0编辑  收藏  举报