C# 读取存储在本地txt中的参数
读取:FormLoad
/**
*
* 初始化算法参数配置
*
* **/
try
{
this.ParamPath = File.ReadAllText(@"./TempData/ParamPath.txt");
textBox3.Text = this.ParamPath;
}
catch
{
}
写入
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "选择参数文件存放目录";
if (folder.ShowDialog() == DialogResult.OK)
{
//MessageBox.Show(folder.SelectedPath);
textBox3.Text = folder.SelectedPath;
ParamPath = folder.SelectedPath;
}
try
{
//如果文件不存在,则创建;存在则覆盖
System.IO.File.WriteAllText(@"./TempData/ParamPath.txt", ParamPath, Encoding.UTF8);
}
catch (Exception exp)
{
MessageBox.Show("参数配置路径写入本地失败-失败原因:" + exp.Message);
}
本文摘自 :https://blog.51cto.com/u