开发者

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

开发者 https://www.devze.com 2023-02-10 03:42 出处:网络
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 tha

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

精彩评论

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