没有File.ReadAllText有什么办法吗?

时间:2009-11-12 16:22:09

标签: c# file-io windows-mobile-5.0

我喜欢开发文件I / O应用程序,而我的新开发平台是Windows Mobile。有没有办法在不使用File.ReadAllText的情况下阅读所有文件?

因为Windows Mobile没有此功能。

2 个答案:

答案 0 :(得分:4)

自己写:

static string ReadAllText(string path) {
    using (var r = new StreamReader(path)) {
        return r.ReadToEnd();
    }
}

答案 1 :(得分:1)

移动框架支持许多文件操作,例如:

string text;
using (StreamReader reader = File.OpenText(fileName)) {
   text = reader.ReadToEnd();
}