C # Paging Read GB text file

Source: Internet
Author: User

Application Scenarios:

A. WhenI am doing BI development test, 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 display.

B. sometimes we use ASCII or ASCII as the delimiter for rows or columns, so that temporary files are used to guide the data to DB, and if there is an error during file import, you need to view the file , the normal editor does not support the line-wrapping, it will 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 reads the contents of the file according to the specified line terminator, and pagesize, and can be converted between text and byte .

SourceCode:

The main code is as follows, using an iterator:

Privateienumerator<string> ReadLines (stringfilename) {/*string line;using (TextReader reader = file.opentext (filename)) {while (line = reader. ReadLine ()) = NULL) yield return line;}*/StringBuilder SB=NewStringBuilder ();using(FileStream fs =file.openread (filename)) {intb =0; while(B=fs. ReadByte ())!=-1){//TextBox3 Store the row Terminatorif(b.tostring () = =TextBox3.Text.Trim ()) {yield returnsb. ToString (); sb. Clear ();}Elsesb. Append (UnicodeEncoding.ASCII.GetString (New byte[] {byte. Parse (B.tostring ())})); }}}

Example:

I tested once, generated 1 billions of rows of data, in the system to display the space occupied 6GB ,

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.

 

C # Paging Read GB text file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.