How can I split a single text file with 1000 lines into multiple smaller files of, for example, 300 lines ? I found two C# code, they feel good, but I'm not able to convert them to vb.net
Code:
using (System.IO.StreamReader sr = new System.IO.StreamReader("path"))
{
int fileNumber = 0;
while (!sr.EndOfStream)
{
int count = 0;
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("other path" + ++fileNumber))
{
sw.AutoFlush = true;
while (!sr.EndOfStream && ++count < 20000)
{
sw.WriteLine(sr.ReadLine());
}
}
}
}
Code:
var reader = File.OpenText(infile);
string outFileName = "file{0}.txt";
int outFileNumber = 1;
const int MAX_LINES = 300;
while (!reader.EndOfStream)
{
var writer = File.CreateText(string.Format(outFileName, outFileNumber++));
for (int idx = 0; idx < MAX_LINES; idx++)
{
writer.WriteLine(reader.ReadLine());
if (reader.EndOfStream) break;
}
writer.Close();
}
reader.Close();