需要添加using System.IO命名空间
if (File.Exists("C:\\1.txt"))
{
MessageBox.Show("文件已存在!");
}
else
{
FileStream fs = new FileStream("C:\\1.txt", FileMode.CreateNew);
StreamWriter sw = new StreamWriter(fs);
sw.Write("你好啊"); //这里是写入的内容
sw.Flush();
}
先引入System.IO的命名空间,然后写如下代码
string file = txtFilePath.Text;
string content = txtContent.Text;
if (!File.Exists(file) == true)
{
MessageBox.Show("存在此文件!");
}
else
{
FileStream myFs = new FileStream(file, FileMode.Create);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(content);
mySw.Close();
myFs.Close();
MessageBox.Show("写入成功");
}
if(File.Exist("路径/A.txt"))
{
MessageBox("提示");
}
else
{
StreamWrite sw = new StreamWrite("路径/A.txt");
SW.Write("fdak;fj");
……
sw.Close();
}
IFeatureClass.CreateFeature()可以创建一个Feature
IFeature.SetValue方法可以写值