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