1、可以读取大文件(2G)2、实现首页、下一页、前一页、末页的跳转4、限制每页显示字符数 1029-4069byte,且用户可自定义该值现在基本功能实现了,但是想用多线程来实现,假如可以同时可以开两个线程,每次可以读2M到到缓冲区
这样子就有一个问题,最后怎么合并呢?或者谁能给个比较好的解决方案啊,感激不尽!意见采纳者另外开贴加100分
这样子就有一个问题,最后怎么合并呢?或者谁能给个比较好的解决方案啊,感激不尽!意见采纳者另外开贴加100分
{
StreamReader sr = new StreamReader(FileName, Encoding.GetEncoding("gb2312"));
int line = 0;
string strline = sr.ReadLine();
while (strline!="")
{
line++;
strline = sr.ReadLine();
}
sr.Close();
}).Start();
使用锁lock
对于读取StreamReader的行定位足够实现动态加载数据了,但是要更改就不是那么容易,毕竟你不是所有数据加载到内存里修改,真要这么做,内存是不够的。要实时插入或者删除文本内容,用StreamWriter是做不到的,等待高手提供API的解决方案。
private int _bufferSize = 16384; private void ReadFile(string filename)
{
StringBuilder stringBuilder = new StringBuilder();
FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); using (StreamReader streamReader = new StreamReader(fileStream))
{
char[] fileContents = new char[_bufferSize];
int charsRead = streamReader.Read(fileContents, 0, _bufferSize); // Can't do much with 0 bytes
if (charsRead == 0)
throw new Exception("File is 0 bytes"); while (charsRead > 0)
{
stringBuilder.Append(fileContents);
charsRead = streamReader.Read(fileContents, 0, _bufferSize);
}
}
}
http://topic.csdn.net/u/20091025/21/76bdeb3b-0825-47af-b5aa-08069e4a6354.html
或者分割文件,存为几个数组.using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace _2_DataSourceArray //显示数组中的数据,用包装器类
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void getData_Click(object sender, EventArgs e)
{
// Uncomment to see what happens with strings...
//string[] items = new string[] { "One", "Two", "Three" }; Item[] items = new Item[] { new Item ( "One" ) ,
new Item ( "Two" ) ,
new Item ( "Three" ) }; dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = items;
} protected class Item
{
public Item(string text)
{
m_text = text;
} public string Text
{
get { return m_text; }
} private string m_text;
} }
}