winform 读取保存配置文件

原文连接:

public static string fileName = System.IO.Path.GetFileName(Application.ExecutablePath);
        public static bool addSetting(string key, string value)
        {
            Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
            config.AppSettings.Settings.Add(key, value);
            config.Save();
            return true;
        }
        public static string getSetting(string key)
        {
            Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
            string value = config.AppSettings.Settings[key].Value;
            return value;
        }
        public static bool updateSeeting(string key, string newValue)
        {
            Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
            string value = config.AppSettings.Settings[key].Value = newValue;
            config.Save();
            return true;
        }

时间: 2024-08-11 09:57:30

winform 读取保存配置文件的相关文章

Winform读取文档。然后创建,奇数行保存一个文档,偶数行保存一个文档

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Text.RegularExpressions; namespace TextModify

java读取.properties配置文件的几种方法

读取.properties配置文件在实际的开发中使用的很多,总结了一下,有以下几种方法(仅仅是我知道的):一.通过jdk提供的java.util.Properties类.此类继承自java.util.HashTable,即实现了Map接口,所以,可使用相应的方法来操作属性文件,但不建议使用像put.putAll这两个方法,因为put方法不仅允许存入String类型的value,还可以存入Object类型的.因此java.util.Properties类提供了getProperty()和setPr

Ctrl+S保存配置文件

java swing程序,Ctrl+S 保存配置文件如何实现呢? 首先增加全局快捷键:  /***  * 增加全局快捷键.<Br>  * Ctrl+S,保存参数到配置文件  */ private void setGlobalShortCuts() { // Add global shortcuts Toolkit toolkit = Toolkit.getDefaultToolkit(); // 注册应用程序全局键盘事件, 所有的键盘事件都会被此事件监听器处理. toolkit.addAWTE

WPF 分享一种设置程序保存配置文件的方法

最近需要做一个配置程序,主要给其他程序做相关配置的小工具. 配置项蛮多的,一般我们都是将各个配置项写到配置文件的节点中,比如App.config文件或者自定义的xml文件. 因为我用的是wpf,MVVM,所以其实界面上的所有数据我都存着ViewModel的实体属性中.比如我们新建一个Model,叫SettingModel,界面上不管做任何更改,其实数据都和SettingModel中一样. 我们将这个SettingModel的内存数据序列化到本地文件.等下次运行程序时,再去反序列化将Setting

java读取properties配置文件总结

java读取properties配置文件总结 在日常项目开发和学习中,我们不免会经常用到.propeties配置文件,例如数据库c3p0连接池的配置等.而我们经常读取配置文件的方法有以下两种: (1).使用getResourceAsStream()方法读取配置文件. (2).使用InputStream()流去读取配置文件. 注意:在使用getResourceAsStream()读取配置文件时,要特别注意配置文件的路径的写法. this.getClass.getResourceAsStream(f

【XML配置文件读取】使用jdom读取XML配置文件信息

在项目中我们经常需要将配置信息写在配置文件中,而XML配置文件是常用的格式. 下面将介绍如何通过jdom来读取xml配置文件信息. 配置文件信息 <?xml version="1.0" encoding="UTF-8"?> <config> <base-config> <stringValue>Hello world</stringValue> <integerValue>8</integ

读取property配置文件

[支持main方法测试] ResourceBundle resourceBundle = ResourceBundle.getBundle("service");        String url = resourceBundle.getString("serviceid");        System.out.println(url); service.properties [配置文件,放在src根目录下] serviceid=1 [不支持中文] 读取prop

Java 读取Properties配置文件

读取Properties配置文件的方法,经常忘记,记录下来备忘一下: package utils; import java.io.IOException;import java.io.InputStream; import java.util.Properties; public class PropertyConfig { private static Properties config; static { config = new Properties(); InputStream in =

java读取properties配置文件

java读取.properties配置文件 这两天做java项目,用到属性文件,到网上查资料,好半天也没有找到一个满意的方法能让我读取到.properties文件中属性值,很是郁闷,网上讲的获取属性值大概有以下方法,以下三种方法逐渐优化,以达到最好的效果以下都以date.properties文件为例,该文件放在src目录下,文件内容为 startdate=2011-02-07 totalweek=25 方法一: public class Stweek { static private Strin