c#创建目录和文件夹,数据写入并生成txt文件
c#创建目录:
// 获取程序的基目录。
System.AppDomain.CurrentDomain.BaseDirectory
// 获取模块的完整路径。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
System.Environment.CurrentDirectory
// 获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
// 获取和设置包括该应用程序的目录的名称。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 获取启动了应用程序的可执行文件的路径。
System.Windows.Forms.Application.StartupPath
// 获取启动了应用程序的可执行文件的路径及文件名
System.Windows.Forms.Application.ExecutablePath
//组成新的路径
string path=System.Windows.Forms.Application.StartupPath+"\\DownFile\\";
//判断该路径下文件夹是否存在,不存在的情况下新建文件夹
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//生成txt文件,将json字符串数据保存到txt文件
string postPath=path+DateTime.Now.ToString("yyyyMMddHHmmss")+".txt";//路径+文件名
byte[] bytes=null;
bytes=Encoding.UTF8.GetBytes(Obj.ToString())//Obj为json数据
FileStream fs=new FileStream(postPath,FileMode.Create);
fs.Write(bytes,0,bytes.Length);
fs.Close();
最新文章
- 几种常见语言的命名空间(Namespace)特性
- 局域网IP段
- express随记01
- Linux:实现Hadoop集群Master无密码登录(SSH)各个子节点
- VMware安装CentOS后网络设置
- js 选择器
- 移动端touch事件获取clientX, clientY
- hdu4578 线段树 三次方,二次方,一次方的值
- checkbox/input文本框与文字对齐
- PHP 文件
- OpenGL ES中MRT应用
- java方法重载和重写
- java连接数据库以及连接参数格式
- C++ 第十课:标准c时间与日期函数
- angular学习笔记(三十)-指令(8)-scope
- lower类的accessCode解读
- UOJ#34. 多项式乘法(NTT)
- C 共享内存封装
- 深入解析QML引擎, 第1部分:QML文件加载
- signal基础