开发者

Setting A String To A .txt's File Contents?

I want to set a string to the entire contents of a file without manually (with my own code) looping through the fi开发者_如何转开发le and adding each line to the string. Is there something built in that will accomplish this?

string asdf = file("aFile.txt");


Looks like you want File.ReadAllText. If you don't pass an encoding in, it will use UTF-8... but make sure that's actually what you want, or specify an encoding yourself.


One of these:

    String FileStuff = File.ReadAllText("MyFile.txt");
    String[] FileLines = File.ReadAllLines("MyFile.txt");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜