博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读写txt文件
阅读量:4348 次
发布时间:2019-06-07

本文共 1789 字,大约阅读时间需要 5 分钟。

public void SetUpdateTime(string strNewDate)        {            try            {                var path =Application.StartupPath + ConfigurationManager.AppSettings["UpdateFile"];                // 判断文件是否存在,不存在则创建,否则读取值显示到窗体                if (!File.Exists(path))                {                    FileStream fs1 = new FileStream(path, FileMode.Create, FileAccess.Write);//创建写入文件                    StreamWriter sw = new StreamWriter(fs1);                    sw.WriteLine(strNewDate);//开始写入值                    sw.Close();                    fs1.Close();                }                else                {                    FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Write);                    StreamWriter sr = new StreamWriter(fs);                    sr.WriteLine(strNewDate);//开始写入值                    sr.Close();                    fs.Close();                }            }            catch (Exception e)            {                LogWrite.ErrorLog(e);            }        }        public DateTime GetUpdatedTime()        {            var reslut = DateTime.MaxValue;            StreamReader sr = null;            try            {                var path = System.Windows.Forms.Application.StartupPath + ConfigurationManager.AppSettings["UpdateFile"];                // 判断文件是否存在,不存在则创建,否则读取值显示到窗体                sr = new StreamReader(path, Encoding.Default);                String line = sr.ReadLine();                if (line != null)                {                    reslut = Convert.ToDateTime(line.ToString());                }            }            catch (Exception e)            {                LogWrite.ErrorLog(e);            }            sr.Close();            return reslut;        }

 

转载于:https://www.cnblogs.com/ChineseMoonGod/p/5193624.html

你可能感兴趣的文章
webpack中‘vant’全局引入和按需引入【vue-cli】
查看>>
Date、String和Timestamp类型转换
查看>>
计算机的组成
查看>>
CSS命名规范
查看>>
初始化构造函数中定义的实体集合,方便嵌套类型的遍历
查看>>
状压dpHDU - 4856
查看>>
java.nio.ByteBuffer 类 缓冲区
查看>>
PL/SQL系列1-PL/SQL介绍
查看>>
关于render函数的总结
查看>>
JavaScript 小刮号
查看>>
BZOJ USACO 银组 水题集锦
查看>>
Android为TV端助力 Linux命令查看包名类名
查看>>
【zabbix】自动注册,实现自动发现agent并添加监控(agent不需要任何配置)
查看>>
[简单到爆]eclipse-jee-neon的下载和安装
查看>>
vector
查看>>
Redis学习之set类型总结
查看>>
栈和队列
查看>>
CSS2-3常见的demo列子总结一
查看>>
XML & JSON---iOS-Apple苹果官方文档翻译
查看>>
[洛谷P2123]皇后游戏
查看>>