读取文件内容字符串中的.NET Compact Framework受 [英] Reading file content to string in .Net Compact Framework

查看:140
本文介绍了读取文件内容字符串中的.NET Compact Framework受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用.NET Compact Framework 2.0的移动设备的应用程序。我试图加载文件的内容为字符串对象,但不知何故,我无法完成它。有一个在就是System.IO.StreamReader 类没有 ReadToEnd的()方法。是否有提供此功能的另一个阶级?


解决方案

  StringBuilder的SB =新的StringBuilder() ; 
使用(StreamReader的SR =新的StreamReader(TESTFILE.TXT))
{
串线;
//读取和文件,直至
的高端显示线//到达文件。
,而((行= sr.ReadLine())!= NULL)
{
sb.AppendLine(线);
}
}
串allines = sb.ToString();


I am developing an application for mobile devices with the .net compact framework 2.0. I am trying to load a file's content to a string object, but somehow I can't get it done. There is no ReadToEnd() method in the System.IO.StreamReader class. Is there another class that provides this functionality?

解决方案

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();

这篇关于读取文件内容字符串中的.NET Compact Framework受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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