解决方案 »

  1.   

    XElement root = XElement.Parse(str);
    root.Save(filePath);
      

  2.   

    遍历数组 循环写到txt里面
     string pathout="C:\\test.txt";
                StreamWriter sw= new StreamWriter(pathout ,true );
                string[] time=new string[3] {"xxx", "xxxx", "xxxxx"};
                for (int i = 0; i <= time.Length; i++)
                {
                    sw.WriteLine(time[i] + " ");
                }
                sw.Close();
                sw.Dispose();
    http://www.cnblogs.com/akwwl/p/3240813.html
      

  3.   

    使用StreamWriter写入txt;
    使用遍历数组,linq to  xml 拼接xml节点并保持写入xml文件;
      

  4.   

      用StreamWriter:
    StreamWriter sw = new StreamWriter("c:\\result.txt");
      

  5.   


    //----------------------------------------------------------------------------------------------------------------
    using System;
    using System.IO;class Test 
    {
        public static void Main() 
        {
            string path = @"c:\temp\MyTest.txt";
            if (!File.Exists(path)) 
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(path)) 
                {
                    sw.WriteLine("Hello");
                    sw.WriteLine("And");
                    sw.WriteLine("Welcome");
                }
            }        // Open the file to read from.           
                using (StreamReader sr = File.OpenText(fileName))
               {
                   string s = "";
                   while ((s = sr.ReadLine()) != null)
                   {
                       Console.WriteLine(s);
                   }
               }        try 
            {
                string path2 = path + "temp";
                // Ensure that the target does not exist.
                File.Delete(path2);            // Copy the file.
                File.Copy(path, path2);
                Console.WriteLine("{0} was copied to {1}.", path, path2);            // Delete the newly created file.
                File.Delete(path2);
                Console.WriteLine("{0} was successfully deleted.", path2);
            } 
            catch (Exception e) 
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
        }
    }------------------------------------------------------------------------------------------------------------
      

  6.   

    先确定你要以什么格式保存数组,然后用文件流或XML对象存入就可以了
      

  7.   

    //先声明string数组
                string[] myStr = new string[3] { "Holman是单身狗\r\n", "Holman是哭狗\r\n", "Holman是热狗\r\n" };
                //创建一个txt文件用Filestream
                using (FileStream myDog = new FileStream(@"C:\Users\ASUSpc\Desktop\Holman.txt", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    //convert str[] to byte[]
                    List<byte> myInfo = new List<byte>();
                    foreach (string item in myStr)
                    {
                        myInfo.AddRange(Encoding.Default.GetBytes(item));
                    }
                    byte[] buffer = myInfo.ToArray();
                    myDog.Write(buffer, 0, buffer.Length);
                }
    ////////入门新狗,代码写得丑,见谅!