This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20862|Reply: 3

[Source] C# exports the string character to the txt document method

[Copy link]
Posted on 7/13/2015 5:15:37 PM | | |

  1. public static string writtxt(string html, string file)
  2.         {
  3.             FileStream fileStream = new FileStream(Environment.CurrentDirectory + "\" + file, FileMode.Append);
  4.             StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.Default);
  5.             streamWriter.Write(html + "\r\n");
  6.             streamWriter.Flush();
  7.             streamWriter.Close();
  8.             fileStream.Close();
  9.             return "ture";
  10.         }
Copy code




Previous:Today, I moved the dormitory to Wuhan Institute of Technology Huaxia College.
Next:C# Scrape and export all hyperlink methods in the web page
Posted on 7/13/2015 6:13:32 PM |
IO
 Landlord| Posted on 7/14/2015 5:11:52 PM |
 Landlord| Posted on 7/14/2015 5:11:56 PM |
  1. /// <summary>
  2.         /// 写入到文件
  3.         /// </summary>
  4.         /// <param name="path">路径</param>
  5.         public static void Test(string path)
  6.         {
  7.             //判断文件是否存在
  8.             if (!File.Exists(path))
  9.             {
  10.                 using (StreamWriter sw = File.CreateText(path))
  11.                 {
  12.                     //第一次写入字符
  13.                     sw.WriteLine("Hello");
  14.                 }
  15.             }
  16.             else {
  17.                 using (StreamWriter sw = File.AppendText(path))
  18.                 {
  19.                     //已经存在则追加
  20.                     sw.WriteLine("This is my file.");
  21.                 }
  22.             }
  23.         }
Copy code

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com