如何使用C#将整个文件读取到字符串? [英] How to read an entire file to a string using C#?
本文介绍了如何使用C#将整个文件读取到字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我明白这可以通过几种方式来完成,比如读取单个字节,然后将它们转换为字符串。
解决方案
string contents = File.ReadAllText(@C:\temp\test.txt);
What is the quickest way to read a text file into a string variable?
I understand it can be done in several ways, such as read individual bytes and then convert those to string. I was looking for a method with minimal coding.
解决方案
How about
string contents = File.ReadAllText(@"C:\temp\test.txt");
这篇关于如何使用C#将整个文件读取到字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文