using System.IO; StreamWriter sw=new StreamWriter("1.txt"); sw.WriteLine("0"); sw.Close();
System.IO.StreamWriter wt = new System.IO.StreamWriter(); wt.Write("0"); wt.Close();
// Create an instance of StreamWriter to write text to a file. // The using statement also closes the StreamWriter. using (StreamWriter sw = new StreamWriter("TestFile.txt")) { // Add some text to the file. sw.Write("0"); sw.Close(); } 先学会看msdn吧
上面少写了 System.IO.StreamWriter wt = new System.IO.StreamWriter("c:\\123.txt"); wt.Write("0"); wt.Close();
System.IO.StreamWriter sw = new StreamWriter(@"C:\abcd.txt"); sw.WriteLine("0"); sw.Flush(); sw.Close();
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\tmp.txt"); sw.Write("0"); sw.Close();
using System; using System.IO;class Test { public static void Main() { if (!File.Exists(strFileName)) { FileStream fs = File.Create(strFileName)) } using (StreamWriter sw = File.CreateText(strFileName)) { sw.WriteLine ("0"); sw.Close(); } } }
StreamWriter sw=new StreamWriter("1.txt");
sw.WriteLine("0");
sw.Close();
wt.Write("0");
wt.Close();
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
sw.Write("0");
sw.Close();
}
先学会看msdn吧
System.IO.StreamWriter wt = new System.IO.StreamWriter("c:\\123.txt");
wt.Write("0");
wt.Close();
sw.WriteLine("0");
sw.Flush();
sw.Close();
sw.Write("0");
sw.Close();
using System.IO;class Test
{
public static void Main()
{
if (!File.Exists(strFileName))
{
FileStream fs = File.Create(strFileName))
}
using (StreamWriter sw = File.CreateText(strFileName))
{
sw.WriteLine ("0");
sw.Close();
} }
}
要引用哪个类,取得当前站点的目录是Server.Path(".")这样吗?
{
sw.Write("你要写的数据"+ Environment.NewLine);
sw.Close();
}
public class Class1:System.Web.UI.Page
{
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public void NewFile(string FileName)
{
String path=Server.MapPath(".")+"TxtFile\\"+FileName+".txt";
StreamWriter sw=new StreamWriter(path);
sw.WriteLine("0");
sw.Close();
} }