1.创建软件界面
2.创建文件路径
string path = Path.GetFullPath("..") + "\\syscfg\\axiscfg.text";
string FilePath= Path.GetFullPath("..") + "\\syscfg";
3.生成文件(先判断text文件的上一层文件是否生成,没有先生成文件夹,再生成文件)
if (Directory.Exists(FilePath))
{
if (!File.Exists(path))
{
FileStream fs = File.Create(path);
MessageBox.Show("文件创建成功");
fs.Close();
fs.Dispose();
}
else
{
MessageBox.Show("文件已经存在");
}
}
else
{
Directory.CreateDirectory(FilePath);
if (!File.Exists(path))
{
FileStream fs = File.Create(path);
MessageBox.Show("文件创建成功");
fs.Close();
fs.Dispose();
}
else
{
MessageBox.Show("文件已经存在");
}
}
4.文件的读取和写入
private void btn_Wtite_Click(object sender, EventArgs e)
{
File.WriteAllText(path,"11111111111111111");
}
private void btn_Read_Click(object sender, EventArgs e)
{
string[] res= File.ReadAllLines(path);
foreach (string item in res)
{
this.textBox1.Text += item;
}
}
5.文件的删除
private void btn_Detel_Click(object sender, EventArgs e)
{
File.Delete(path);
}