仿Ini文件的读写

//因为在WinCe平台上开发软件,但是WinCe平台不支持Ini功能,所以就自己写了一个!using System.Collections.Generic;using System.IO;using System.Text;using System;namespace myIniJQ{ /// /// 创建ini格式的txt文档 ///
摘要由CSDN通过智能技术生成
//因为在WinCe平台上开发软件,但是WinCe平台不支持Ini功能,所以就自己写了一个!


using System.Collections.Generic;
using System.IO;
using System.Text;
using System;

namespace myIniJQ
{
    /// <summary>
    /// 创建ini格式的txt文档
    /// </summary>
    public class winEcIniJQ
    {
        private string Path;
        /// <summary>
        ///  初始化winEc文件读写函数
        /// </summary>
        /// <param name="Path"></param>
        public winEcIniJQ(string Path)
        {
            Path = Path.Replace("file:\\", "");
            this.Path = Path;
        }


        /// <summary>
        /// 读取保存(因为偶尔会出现莫名错误,所以先读取一遍,然后再按照utf-8的格式保存下来,确保文件万无一失)
        /// </summary>
        /// <returns></returns>
        private bool WinNewRead()
        {
            bool FileState = false;
            string strRead = "";
            Path = Path.Replace("file:\\", "");
            try
            {
                if (File.Exists(Path))
                {
                    List<string> addstrlist = new List<string>();
                    StreamReader streamread = new StreamReader(Path, Encoding.UTF8);//打开文件
                    while ((strRead = streamread.ReadLine()) != null)
                    {
                        if (strRead != "")
                        {
                            addstrlist.Add(strRead);
                        }
                    }
                    streamread.Close();
                    StrFlush(addstrlist);
                    FileState = true;
                }
                return FileState;

            }
            catch (Exception ex)
            {
                FileState = false;
                //记录异常
                string startError = "winEcIniJQ.WinNewRead函数异常发生时间:" + DateTime.Now.ToString("HHmmss") + " " + ex.InnerException.ToString();
                //因为无法预知的异常,并且在出现异常的时候显控无法在窗体上提示,所以我们要创建一个异常文件,来记录当前发生的异常;
                string Errorurl = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\winEcIniJQError.txt";
                Errorurl = Errorurl.Replace("file:\\", "");
                StreamWriter stream = new StreamWriter(Errorurl, true);
                stream.WriteLine(startError);
                stream.Flush();
                stream.Close();
                return FileState;
            }

        }




        /// <summary>
        /// 读取ini格式的文件
        /// </summary>
        /// <param name="HeadName">文件头索引</param>
        /// <param name="Body">文件内容索引</param>
        /// <param name="End">文件内容</param>
        /// <returns></retur
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值