string strTemp = TextBox1.Text.ToString().Trim(); //获取文件要存放的位置和文件名
File.Create(strTemp); //创建一个文件
if(File.Exists(strTemp)) //判断文件是否存在
{
StreamWriter b = new StreamWriter(strTemp,true) ; //给文件里写东西
b.Write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") ;
b.Close();
}
提示错误文件正在使用
//////////////////////////////////////////////////
怎么解决导出文本文件问题呢,请大家指点。
File.Create()已经创建了一个FileStream,所以,在你那个FileStream没有close前是不能对文件进行操作的
FileStream fs=File.Create(strTemp);
byte [] buf=Encoding.Default.GetBytes("sfdgsdfg");
fs.Write(buf,0,buf.Length)
string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}