【问题标题】:Not reading the content of files in wpf [closed]不读取 wpf 中文件的内容 [关闭]
【发布时间】:2012-12-31 10:28:03
【问题描述】:
        var dir = new DirectoryInfo(Path);
        foreach (FileInfo flInfo in dir.GetFiles())
        {
            String name = flInfo.Name;
            long size = flInfo.Length;
            DateTime creationTime = flInfo.CreationTime;
            const int counter = 0;
            int count = counter + 1;
        }

我正在获取路径但没有读取内容和文件信息

【问题讨论】:

  • 添加 File.ReadAllText(flInfo.Name) 怎么样? msdn.microsoft.com/en-us/library/s2tte0y1.aspx
  • 不知道这和WPF有什么关系
  • 通常的方式。 “这与 WPF 有关,因为海报不知道他在做什么”。因此,他不明白 WPF 究竟是什么。

标签: c# file fileinfo directoryinfo


【解决方案1】:
  1. 我不明白,为什么需要计数器变量
  2. 您不要尝试阅读内容。 如果要读取文件,请使用流读取它:

    using (StreamReader reader = flInfo.OpenText())
    {
    Console.WriteLine(reader.ReadToEnd());
    }
    

【讨论】:

  • 嗨 zzfima 我添加了计数器来检查文件是否正在读取。我想读取目录中的所有文件,而不是单个文件,您可以修改代码并添加它吗?我没有从目录中获取文件不是文件读取问题
  • 你不要增加“counter”变量(至少在当前代码和平中),注意。那么,您的问题是从目录中获取文件?
  • 请留下柜台问题不是问题。我没有阅读内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
  • 1970-01-01
相关资源
最近更新 更多