private void button1_Click(object sender, EventArgs e)
{
FileStream fi;
try
{
fi = File.Create(textBox1.Text); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
byte[] content = new UTF8Encoding(true).GetBytes(textBox2.Text);
try
{
fi.Write(content, 0, content.Length);
fi.Flush();
MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
catch (Exception ex)
{
MessageBox.Show(ex.Message); }
finally
{
fi.Close();
}
错误提示是没有跟fi局部变量赋值!可是上面有跟他赋值啊,我不懂了
{
FileStream fi;
try
{
fi = File.Create(textBox1.Text); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
byte[] content = new UTF8Encoding(true).GetBytes(textBox2.Text);
try
{
fi.Write(content, 0, content.Length);
fi.Flush();
MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
catch (Exception ex)
{
MessageBox.Show(ex.Message); }
finally
{
fi.Close();
}
错误提示是没有跟fi局部变量赋值!可是上面有跟他赋值啊,我不懂了
解决方案 »
- 求高人指点!在C#中在A窗体中定义了Datagridview,如何在B窗体的Datagridview中显示A窗体的Datagridview中所有的列名?
- C#验证
- 磁卡串口监听问题
- C#中 ReadPrint函数怎么用
- 打开form设计视图时的错误,请高手指点!
- 初学者请求帮助
- 请朋友们提示一个.NET空间,并支持sql server
- vb6中的Variant类型在vc#中如何舍?
- 如何使C#写的NT Service程序,可以具有Web Service的功能,或是可以被其他程序呼叫?
- !!!!动态添加列的问题。各位帮帮忙啊~~~~~~~~~~~~
- C# winform,toolStrip中添加的toolStripButton按钮怎么设置鼠标经过颜色?
- 近来没事写个QQ轰炸机,高手路过
FileStream fi = null;
{
String 保存路径 = @System.Environment.CurrentDirectory + "\\修改日记";
if (Directory.Exists(保存路径))
{
String 保存文件名 = @保存路径 + "\\" + 时间.ToLongDateString() + ".txt ";
FileInfo 文件 = new FileInfo(保存文件名);
if (!文件.Exists) { FileStream 创建或覆盖 = File.Create(保存文件名); 创建或覆盖.Flush(); 创建或覆盖.Close(); }
//{ 文件.Create(); }FileStream 创建只写文件 = 文件.OpenWrite(); 创建只写文件.Close();
//StreamWriter 写入 = File.AppendText(保存文件名);//以可以追加文本的方式打开文件流
StreamWriter 写入 = new StreamWriter(保存文件名, true);//以可以追加文本的方式打开文件流
写入.WriteLine(输出内容); 写入.Flush(); 写入.Close();
}
else
{
Directory.CreateDirectory(保存路径);
String 保存文件名 = @保存路径 + "\\" + 时间.ToLongDateString() + ".txt ";
FileStream 创建或覆盖 = File.Create(保存文件名);
创建或覆盖.Flush(); 创建或覆盖.Close();
StreamWriter 写入 = new StreamWriter(保存文件名);//不可追加文本
写入.WriteLine(输出内容); 写入.Flush(); 写入.Close();
}
}
就当参考吧