保存并从文本文件中获取数据 [英] Save and fetch data from text file

查看:75
本文介绍了保存并从文本文件中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#点网将数据保存到文本文件中以及如何从文本文件中获取数据?

How to save data in a text file and how to fetch data from text file using c# dot net?

推荐答案

周围有很多教程.例如,参见如何:读取和写入文本文件" [
There are a lot of tutorials around. See, for instance "How To: Reading and Writing Text Files"[^].


U可以使用名称Space正在使用system.IO
然后使用此代码
U can use name Space Using system.IO
then use this code
//This code is used to write data into .txt file...

FileStream fs = new FileStream("E:\\a.txt", FileMode.Create, FileAccess.Write);
StreamWriter write = new StreamWriter(fs);
string a_variable = "more advanced services to mobile or nomadic computing devices";
write.Write(a_variable);
write.Close();
fs.Close();


//This code is used to read data from.txt file...

FileStream fs1 = new FileStream("E:\\a.txt", FileMode.Open);
StreamReader read = new StreamReader(fs1);
string b = read.ReadToEnd();
Console.WriteLine(b);
read.Close();
fs1.Close();


我将从 TextReader [ ^ ]类将保存的数据返回到程序中.

或者,根据应用程序中可用的数据, FileStream [ ^ ]可能就是您想要的.
I''d start with the TextWriter[^] class. As soon as you have successfully written a file, you can proceed to the TextReader[^] class to get the saved data back into your program.

Or, depending on what data you have available in your application, FileStream[^] could be what you''re after.


这篇关于保存并从文本文件中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆