我正在使用.net compact Framework2.0为移动设备开发一个应用程序。我试图将文件的内容加载到string对象中,但不知何故无法完成。System.IO.StreamReader
类中没有ReadToEnd()
方法。是否有其他类提供此功能?
发布于 2011-07-28 04:33:46
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
sb.AppendLine(line);
}
}
string allines = sb.ToString();
发布于 2012-07-24 05:27:58
string text = string.Empty;
using (StreamReader streamReader = new StreamReader(filePath, Encoding.UTF8))
{
text = streamReader.ReadToEnd();
}
另一种选择:
string[] lines = File.ReadAllLines("file.txt");
https://gist.github.com/paulodiogo/9134300
很简单!
发布于 2011-07-28 04:34:27
File.ReadAllText(file)
你要找的是什么?
如果您喜欢将其按行分解为数组,也可以使用File.ReadAllLines(file)
。
https://stackoverflow.com/questions/6850850
复制相似问题