What if I don't want to store too much data in each file?
It is a good way to set the number of data entries in a file. How can you ensure that the number of data entries does not exceed the limit when writing data to a TXT file? How can I store more than one file in another TXT file?
Next I will introduce you to a simple method (of course, it is better not to rule out, I am here for reference only)
1 if ((icount % 10000 == 0) && (icount / 10000 > 0)) 2 { 3 sw.Close(); 4 flag = flag + icount / 10000; 5 path = outpath + + flag + ".txt"; 6 try 7 { 8 FileStream fs = new FileStream(path, FileMode.CreateNew); 9 fs.Close();10 11 12 }13 catch (Exception e)14 {15 //System.Windows.Forms.MessageBox.Show(e.Message.ToString());16 17 }18 //System.Windows.Forms.MessageBox.Show("111");19 sw = new StreamWriter(path, true);20 flag = 1;21 }
Of course, this value can be changed as needed.
Create and write TXT files. Each file can contain 1 million data records. Split over data entries into multiple files