The example in this article describes how C # pagination reads a GB text file. Share to everyone for your reference. Specific as follows:
First, the application scenario:
①. When I am doing BI development testing, it is possible to face the number of gigabytes of the source file, if you use a generic text editor, it will be stuck, or wait a long time to show up.
②. Sometimes, we use ASCII (01) or ASCII (02) as the delimiter of the row or column, such temporary files used to guide the data to the DB, if the file import process errors, need to view the file, the normal editor does not support line wrapping, it would be very scary.
To address these two requirements, I used C # to complete a simple WinForm application.
Feature List:
1. Based on the number of lines configured, write the test file, specify the line terminator, and the column delimiter is temporarily unused.
2. According to the specified line terminator, and pagesize, paging reads the contents of the file, and can be converted between text and byte.
Second, the implementation of code:
The main code is as follows, using an iterator:
The code is as follows:
Private ienumerator<string> ReadLines (string filename)
{
/*
String line;
using (TextReader reader = file.opentext (filename))
{
while (line = reader. ReadLine ()) = null)
yield return line;
}
*/
StringBuilder sb = new StringBuilder ();
using (FileStream fs = file.openread (filename))
{
int b = 0;
while ((B=fs. ReadByte ())!=-1)
{
TextBox3 Store the row terminator
if (b.tostring () = = TextBox3.Text.Trim ())
{
Yield return SB. ToString ();
Sb. Clear ();
}
Else
Sb. Append (UnicodeEncoding.ASCII.GetString (new byte[] {byte. Parse (B.tostring ())});
}
}
}
Examples are shown below:
I tested it once, generating 100 million of rows of data, showing a space of 6GB in the system,
I try to read and write, without the condition of Kaka.
Can be further updated:
displayed to the GridView according to the column lines delimiter, which is clearer.
You can read the file from the forward.
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Paging Read GB text file instance
This address: http://www.paobuke.com/develop/c-develop/pbk23331.html
Related Content C # developing a Send template message C # uses SELENIUM+PHANTOMJS to fetch data c#6.0 10 features in the application and summary of the actions initialized with the initializer of an object or collection in C #
C #, ASP. NET Universal extension Tool class logicsugarwebserviceμ?? Òμ¥ ax°?ó?úμ÷ó?? ¨c# Simple e-mail method C # Delegate Realistic example analysis
C # Paging Read GB text file instance