csharp读写properties文件

这篇博客介绍了如何在C#中读写properties文件。首先,通过添加using和使用工具类来实现编码操作。接着,详细讲解了读取properties文件的代码,包括判断文件是否存在、读取文件内容、按行拆分并解析键值对。文章还提到在文件名不含路径的情况下,WriteAllText是否会自动创建文件夹,并讨论了在VS2013中调试时遇到的问题及解决方法。
摘要由CSDN通过智能技术生成

编码

添加using

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Text;

PropertiesConfig

  class PropertiesConfig {
    private static Hashtable _ht = new Hashtable(16);
    static PropertiesConfig() {
      var ht = new Hashtable();
      string file = @"app.properties";
      if (!File.Exists(file)) { 
        //将变量列入到配置文件中
        _ht=initProperties();
        save(file,_ht);
      } else {
        //加载配置文件,验证配置文件,保存配置文件
        _ht = load(file);
        if (validate()) {
          save(file, _ht);
        }
      }
    }

    private static Hashtable initProperties() {
      _ht["project.name"] = "合光机器人知识库";
      _ht["manager.url"] = "http://ibotcluster.online.uairobot.com/manager";
      return _
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值