如何在C#类中创建读取删除文本文件 [英] How Do I Create Read Delete A Text File In C# Classes
本文介绍了如何在C#类中创建读取删除文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,请你帮我解决它非常重要的事情......
hello could you please help me its very important...
推荐答案
只要你付出这么少的努力,你就会觉得不舒服。请看这里: https://msdn.microsoft.com/en -us / library / system.io%28v = vs.110%29.aspx 。
这足以让你做到这一切拥有,甚至没有询问任何细节。文档非常清楚。
-SA
With so little effort on your side, it doesn't feel comfortable to answer in detail. Look here: https://msdn.microsoft.com/en-us/library/system.io%28v=vs.110%29.aspx.
This is more than enough to do it all on your own, not even asking about any detail. The documentation is crystal clear.
—SA
创建文本文件可以通过Stream完成作家。
StreamWriter sw = new StreamWriter(@myFile.txt);
sw.WriteLine(some text);
sw.Close();
阅读文本文件可以使用StreamReader或命名空间System.IO来完成;
StreamReader sr = new StreamReader(@myFile.txt);
string text = sr.ReadLine();
label1.Text = text;
或
String text = System.IO .File.ReadAllLines(@myFile.txt);
label1.Text = text;
要删除文本文件,请使用System。 IO.File
System.IO.File.Delete(@myFile.txt);
希望这有帮助 - CCB
Creating text files can be done with Stream Writer.
StreamWriter sw = new StreamWriter(@"myFile.txt");
sw.WriteLine("some text");
sw.Close();
Reading text files can be done with StreamReader or with the namespace System.IO;
StreamReader sr = new StreamReader(@"myFile.txt");
string text = sr.ReadLine();
label1.Text = text;
Or
String text = System.IO.File.ReadAllLines(@"myFile.txt");
label1.Text = text;
To delete text files use System.IO.File
System.IO.File.Delete(@"myFile.txt");
Hope this helps - CCB
这篇关于如何在C#类中创建读取删除文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文