.Net初学者课程:如何在文件中添加文本

如何在一个文件中添加文本的一行代码?

File.AppendAllText(@"c:\path\file.txt", "text content" + Environment.NewLine);

好了!不需要在 C# 中打开 StreamWriter 和其他所有内容,这只需一行代码即可完成。

查看微软文档:https://docs.microsoft.com/fr-fr/dotnet/api/system.io.file.appendalltext

Join the conversation

You need an account to comment on this article. Creating one is free and takes under a minute.

  • The XMLTV file, free to download every day
  • Comment on articles and reply to other readers
  • Get an e-mail when an article you follow is updated

No comments yet.

Une erreur s'est produite. Cette application peut ne plus répondre jusqu'à ce qu'elle soit rechargée.Veuillez contacter l'auteur. Reload 🗙