c#文本文件保存配置

一、读取配置函数

private void loadAddressInfo()
		{
			this.localAddressInfo.province = -1;
			this.localAddressInfo.city = -1;
			this.localAddressInfo.dis = -1;
			if (File.Exists(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt"))
			{
				StreamReader streamReader = new StreamReader(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt", Encoding.GetEncoding("GB2312"));
				string text = "";
				try
				{
					while (text != null)
					{
						text = streamReader.ReadLine();
						if (text != null && !text.Equals(""))
						{
							string[] array = text.Split(new char[]
							{
								':'
							});
							if (array.Length == 2)
							{
								if (array[0] == "realName")
								{
									this.tb_realName.Text = array[1].Replace("&", "\r\n");
								}
								if (array[0] == "mobile")
								{
									this.tb_phone.Text = array[1].Replace("&", "\r\n");
								}
								if (array[0] == "solidFirst")
								{
									this.tb_solidFirst.Text = array[1].Replace("&", "\r\n");
								}
								if (array[0] == "solidSec")
								{
									this.tb_solidSec.Text = array[1].Replace("&", "\r\n");
								}
								if (array[0] == "province")
								{
									if (array[1] != "")
									{
										this.localAddressInfo.province = int.Parse(array[1]);
									}
									else
									{
										this.localAddressInfo.province = -1;
									}
								}
								if (array[0] == "city")
								{
									if (array[1] != "")
									{
										this.localAddressInfo.city = int.Parse(array[1]);
									}
									else
									{
										this.localAddressInfo.city = -1;
									}
								}
								if (array[0] == "dis")
								{
									if (array[1] != "")
									{
										this.localAddressInfo.dis = int.Parse(array[1]);
									}
									else
									{
										this.localAddressInfo.dis = -1;
									}
								}
								if (array[0] == "edittextarea")
								{
									this.tb_edittextarea.Text = array[1];
								}
								if (array[0] == "postalcode")
								{
									this.tb_postalcode.Text = array[1];
								}
							}
						}
					}
				}
				catch (Exception var_3_2FF)
				{
				}
				this.first_flag = false;
				streamReader.Close();
			}
		}

2、保存配置函数

private void btn_saveYYInfo_Click(object sender, EventArgs e)
		{
			if (!File.Exists(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt"))
			{
				File.Create(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt").Close();
			}
			StreamWriter streamWriter = null;
			FileStream fileStream = null;
			try
			{
				fileStream = new FileStream(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt", FileMode.Create, FileAccess.Write);
				streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
				streamWriter.Flush();
				streamWriter.BaseStream.Seek(0L, SeekOrigin.Begin);
				streamWriter.WriteLine("realName:" + this.tb_realName.Text);
				streamWriter.WriteLine("mobile:" + this.tb_phone.Text);
				streamWriter.WriteLine("province:" + this.cbb_province.SelectedIndex);
				streamWriter.WriteLine("city:" + this.cbb_city.SelectedIndex);
				streamWriter.WriteLine("dis:" + this.cbb_dis.SelectedIndex);
				streamWriter.WriteLine("edittextarea:" + this.tb_edittextarea.Text);
				streamWriter.WriteLine("postalcode:" + this.tb_postalcode.Text);
				streamWriter.Flush();
				streamWriter.Close();
				streamWriter.Dispose();
				fileStream.Close();
				fileStream.Dispose();
				MessageBox.Show("暂存预约地址信息成功!");
			}
			catch (Exception var_2_17C)
			{
				streamWriter.Close();
				streamWriter.Dispose();
				fileStream.Close();
				fileStream.Dispose();
			}
		}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值