|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace SparkAPI.Common.File
{
/// <summary>
///
/// </summary>
public class FileSplitter
{
/// <summary>
///
/// </summary>
/// <param name="inputfileName"></param>
/// <param name="outputFileName"></param>
/// <param name="lines"></param>
public static void SplitFile(string inputfileName, string outputFileName, int lines)
{
StringBuilder output = new StringBuilder();
int lineCount = 0;
StreamReader file = null;
try
{
file = new StreamReader(inputfileName);
string line;
do
{
line = file.ReadLine();
if (line != null)
{
lineCount++;
output.AppendLine(line);
}
} while ((line != null) && (lineCount < lines));
}
finally
{
if (file != null) file.Close(); //Close file stream even if there is an error
}
if (output.Length > 0)
{
System.IO.File.WriteAllText(outputFileName, output.ToString());
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Paul Francis currently works as a senior engineer at The Trade Desk.
He holds an undergraduate Honours degree in Finance, and is near completion of a Ph.D. in Market Microstructure, specialising in order flow modelling, and market data processing, reconstruction and analytics.
He is also the creator of Sharp Spark (Spark API SDK), an open source component designed to facilitate the processing of real-time market data from the Spark API:
http://sourceforge.net/projects/sparkapi
Paul lives in Sydney, Australia.