C# IO包

来源:百度知道 编辑:UC知道 时间:2024/06/05 23:45:13
using System.IO;
try
{
fs = File.Create(@"F:\" + textBox1.Text+@".txt");
byte[] content = new UTF8Encoding(true).GetBytes(textBox2.Text);
fs.Write(content,0,content.Length);
fs.Flush();
MessageBox.Show("保存成功", "保存完毕");
fs.Close();
}
catch
{
MessageBox.Show("代码出错", "建立文件出现错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
return;
}
finally
{

}

//fs实例为什么可以接受对象?
//fs = File.Create(@"F:\" + textBox1.Text+@".txt");
//fs.Write(content,0,content.Length);
//这个方法传入的CONTENT变量 干什么去?

fs是filestream定义的,File.Create()是静态方法,用于接受地址,返回一个filestream对象,fs.Write(content,0,content.Length); 用于使用从缓冲区读取的数据将字节写入该流,msdn上面介绍得很清楚,你去看看