小编mec*_*cum的帖子

读取和修改大文本文件3-5GB

我有一个相当大的文件,包含数百万行,需要检查并删除文件中的损坏行.

我无耻地尝试过File.ReadAllLines但是没有用.然后我尝试在原始文件中读取以下行并写入新文件.虽然它可以完成这项工作,但它可以在几个小时内完成(5+).我已经阅读了有关使用缓冲区的信息,这听起来是唯一的选择,但我如何以这种方式保持线路完整性?

解决方案: StreamWriter移动到while之外.使用count而不是split.

 using (FileStream inputStream = File.OpenRead((localFileToProcess + ".txt")))
 {
    using (StreamReader inputReader = new StreamReader(inputStream, System.Text.Encoding.GetEncoding(1254)))
    {
       using(StreamWriter writer=new StreamWriter(localFileToProcess,true,System.Text.Encoding.GetEncoding(1254)))
       {
          while (!inputReader.EndOfStream)
          {
             if ((tempLineValue = inputReader.ReadLine()).Count(c => c == ';') == 4)
             {
                 writer.WriteLine(tempLineValue);
             }
             else
                 incrementCounter();
          }
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# filestream streamwriter file-handling streamreader

5
推荐指数
1
解决办法
679
查看次数

BindingExpression路径错误

有很多类似的问题,我从这些问题中尝试了很多答案,但到目前为止没有任何帮助.我不明白错误信息实际意味着什么.错误信息是;

System.Windows.Data Error: 40 : BindingExpression path error: 'CategoryModel' 
property not found on 'object' ''String' (HashCode=-57655201)'.
BindingExpression:Path=CategoryModel.CategoryList; DataItem='String'
(HashCode=-57655201); target element is 'TextBlock' (Name=''); target property is
'Text' (type 'String')
Run Code Online (Sandbox Code Playgroud)

CategoryList包含一个已满的类别的字符串列表(从调试中检查).我的xaml在下面,

<ListView x:Name="categoryListView" HorizontalAlignment="Left" Width="56" Height="156" 
              ItemsSource="{Binding Path=CategoryModel.CategoryList}" 
              DisplayMemberPath="CategoryModel.CategoryList" 
              SelectedValue="{Binding Path=CategoryModel.SelectedCategory}"
              VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
</ListView>
Run Code Online (Sandbox Code Playgroud)

xaml设计看起来不错,应用程序运行良好,但没有任何东西被填满.应该在初始化时填充categoryList.它实际填充但listView没有显示任何内容.

编辑:

CategoryModel;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecorderApp.Model
{
public class CategoryModel : INotifyPropertyChanged
{
    private String _selectedCategory;
    private String _recordTitle;
    private String _systemInfoLabel;


    private …
Run Code Online (Sandbox Code Playgroud)

c# wpf binding

2
推荐指数
1
解决办法
1万
查看次数