I put together an app for my company which splits large text files (3gb+) into two files so that some of our other software may work with the files. This app was done in VB.
I was recently introduced to C# (last week) and was expecting it to be faster / more efficient. But when I finished the C# app and ran it, it took approximately the same amount of time.
So I'm wondering if the method of opening, reading, and writing data I chose is inefficient and if there is a preferred, better way of doing so. It seems like I've seen several different ways of accomplishing this from searching the internet
That's the basic gist of it. Is there anything I can do to speed it up? Thanks
I was recently introduced to C# (last week) and was expecting it to be faster / more efficient. But when I finished the C# app and ran it, it took approximately the same amount of time.
So I'm wondering if the method of opening, reading, and writing data I chose is inefficient and if there is a preferred, better way of doing so. It seems like I've seen several different ways of accomplishing this from searching the internet
Code:
string InputPath = this.lblInput.Text;
string OutputPath = this.lblOutput.Text;
string InputFileName = Path.GetFileNameWithoutExtension(InputPath);
string OutputFileName1 = OutputPath+"\\"+InputFileName+"-split1.dan";
string OutputFileName2 = OutputPath+"\\"+InputFileName+"-split2.dan";
FileStream InputFile;
FileStream OutputFile;
InputFile = new FileStream (InputPath,FileMode.OpenOrCreate,FileAccess.Read);
StreamReader InputStream = new StreamReader(InputFile);
OutputFile = new FileStream(OutputFileName1,FileMode.CreateNew,FileAccess.Write);
StreamWriter OutputStream = new StreamWriter(OutputFile);
currentLine = InputStream.ReadLine();
while (currentLine != null)
{
...
//if at position to split file
{
OutputFile.close()
OutputFile = new FileStream(OutputFileName2,FileMode.CreateNew,FileAccess.Write);
OutputStream = new StreamWriter(OutputFile);
}
OutputStream.WriteLine(currentLine);
currentLine = InputStream.ReadLine();
Application.DoEvents();
}
OutputStream.Close();
InputStream.Close();
That's the basic gist of it. Is there anything I can do to speed it up? Thanks