怎么用C#创建一个文本文件,并写入0

解决方案 »

  1.   

    using System.IO;
    StreamWriter sw=new StreamWriter("1.txt");
    sw.WriteLine("0");
    sw.Close();
      

  2.   

    System.IO.StreamWriter wt = new System.IO.StreamWriter();
                wt.Write("0");
                wt.Close();
      

  3.   

    // 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吧
      

  4.   

    上面少写了            
    System.IO.StreamWriter wt = new System.IO.StreamWriter("c:\\123.txt");
    wt.Write("0");
    wt.Close();
      

  5.   

    System.IO.StreamWriter sw = new StreamWriter(@"C:\abcd.txt");
                sw.WriteLine("0");
                sw.Flush();
                sw.Close();
      

  6.   

    System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\tmp.txt");
    sw.Write("0");
    sw.Close();
      

  7.   

    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();
            }    }
    }
      

  8.   

    Server.Path(".")
    要引用哪个类,取得当前站点的目录是Server.Path(".")这样吗?
      

  9.   

    using (StreamWriter sw = new StreamWriter(@"d:\\ins\\MyText.txt", true, System.Text.Encoding.GetEncoding("gb2312")))
                            {
                                sw.Write("你要写的数据"+ Environment.NewLine);
                                sw.Close();
                            }
      

  10.   

    谢谢,搞定了
    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();
    } }