0

C# の streamReader 関数を使用してテキスト ファイル (データベースにエクスポートするファイルの場所を含む) を読み込んでいるときに、コマンド プロンプト ウィンドウ (コンソール アプリケーション) に表示されるコードに確認メッセージを追加するにはどうすればよいですか?ファイルが読み取られ、エクスポートされたことがわかりますか?

public class Script
{
    public static void Main(string[] args)
    {
        // Prepare the type that will handle all of the exporting needs
        FileExporter exporter = new FileExporter();

        try
        {
            //create an instance of StreamReader to read from a file.
            //The using statemen also closes the StreamReader.
            using (StreamReader sr = new StreamReader("ScriptFile.txt"))
            {
                string filePath;
                //read and display lines from the file until the end of
                //the file is reached.
                while ((filePath = sr.ReadLine()) != null)
                {
                    // Throw error if file does not exists to terminate the process.
                    if (!File.Exists(filePath))
                    {
                        string msg = string.Format("File not found at {0}.", filePath);
                        throw new FileNotFoundException(msg);
                    }

                    // Set the name of the export to be the name of the file.
                    string exportName = new FileInfo(filePath).Name;

                    // Export image as an SHP file if the extension matches.
                    if (filePath.Contains(".shp"))
                    {
                        exporter.processSHP(filePath, exportName, "");
                        //need confirmation that exporter.processSHP occured <<<-----***
                    }
                    else
                    {
                        string fileExtension = filePath.Split('.')[filePath.Split('.').Length - 1];

                        exporter.processIMG(filePath, exportName, "", fileExtension); 
                        //need confirmation that exporter.processIMG occured <<<-----***
                    }
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(
                string.Format("Process terminated. An error has occurred: {0}", e.ToString()));
        }
    }
4

4 に答える 4

9

これを追加:

Console.WriteLine("Done reading & Exporting");

その上

}
catch (Exception e)
{
于 2009-11-10T14:07:01.720 に答える
1

実際に表示したい場合は、Console.ReadKey()を忘れないでください。

于 2009-11-10T14:15:30.603 に答える
0

フラッシュを使用してから、ライター オブジェクトを閉じます。

次に、完了をコンソールに書き込みます。

于 2009-11-10T14:07:28.890 に答える
0

ファイルを最後まで読み、一致するものを探した後 (エクスポートが発生し、一致が見つかったことを知らせるブール値のようなものがあると仮定します)、streamreader で EndOfStream プロパティをチェックし、メッセージを出力できます。または、一致値をチェックして、true が返されたかどうかを確認することもできます。

于 2009-11-10T14:09:06.000 に答える