gpt4 book ai didi

c# - 将文本文件数据存储在变量中

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:52 24 4
gpt4 key购买 nike

是否可以将文本文件数据存储在只知道其扩展名的变量中?我在想类似的东西

string path = @"D:\MyTest";
var txt = File.ReadAllLines(path + "*.txt");

最佳答案

如果你想查找扩展名为.txt的文件,如果找到了,加载内容:

  string path = @"D:\MyTest";

// Please, notice that you'll have an array string[] txt
// If you want just String txt output (not array) change ReadAllLines to ReadAllText
var txt = Directory
.EnumerateFiles(path, "*.txt")
// If you can have many text files you may want to add a filter here:
// .Where(file => ...)
.Select(file => File.ReadAllLines(file))
.FirstOrDefault();

关于c# - 将文本文件数据存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40019262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com