したがって、基本的にディレクトリ内のすべてのテキストファイルをチェックする関数呼び出し分類子があります。50行を超える単語を含むテキストファイルがある場合は、そのテキストファイルをText_Classificationという他のクラスを使用してタイプに分類します。これは正しいと確信しています。エラーがありません。分類後、そのテキストファイルをクリーンアップし、そのテキストファイルの最初の新しい行として「Lines」を書き込む必要があります(これは他のクラス用なので、気にしないでください:))。try{}
しかし、例外が発生しました。これは、ブロックに何か問題があることを意味します。
なぜですか?
static void classifer(object state) {
Console.WriteLine("Time to check if any log need to be classified");
string[] filename = Directory.GetFiles(@"C:\Users\Visual Studio 2010\Projects\server_test\log");
foreach(string textfile_name in filename) {
var lineCount = File.ReadAllLines(textfile_name).Length;
if(lineCount > 50) {
Console.WriteLine("Start classifying 1 of the logs");
Text_Classification classifier = new Text_Classification(textfile_name, 1);
string type = classifier.passBack_type(); //this function passes back the type of the log(text file)
Console.WriteLine(type);
try {
TextWriter tw = new StreamWriter(textfile_name); //clean the text file
tw.WriteLine(" ");
tw.Close();
TextWriter tw2 = new StreamWriter(textfile_name, true); //append <Lines> as the first new line on the text file
tw2.WriteLine("Lines");
tw2.Close();
}
catch {
Console.WriteLine("cant re-write txt");
}
}
}
}