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
{
//如果文件不存在,則創(chuàng)建;存在則覆蓋
System.IO.File.WriteAllText(@"./TempData/ParamPath.txt", ParamPath, Encoding.UTF8);
}
catch (Exception exp)
{
MessageBox.Show("參數配置路徑寫入本地失敗-失敗原因:" + exp.Message);
}
本文摘自 :https://blog.51cto.com/u