StreamReader С#

Как при чтении текстового файла (который содержит расположение файла для экспорта в базу данных) с помощью функции 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()));
        }
    }

person jason    schedule 10.11.2009    source источник
comment
не могли бы вы опубликовать пример кода того, что вы делаете? Я не совсем понимаю... не сделает ли это команда Console.WriteLine?   -  person sebagomez    schedule 10.11.2009
comment
Вопрос в том виде, в котором он сформулирован, не имеет ничего общего с темой, а только спрашивает, как писать в окно concole. Просьба уточнить.   -  person 3Dave    schedule 10.11.2009


Ответы (4)


Добавь это:

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

над

}
catch (Exception e)
{
person Zenuka    schedule 10.11.2009

Не забудьте Console.ReadKey(), если вы действительно хотите увидеть его там.

person Woot4Moo    schedule 10.11.2009

используйте флеш, а затем закройте объект писателя.

затем напишите в консоль.

person Saar    schedule 10.11.2009
comment
На самом деле, Close должно быть достаточно. Но вам следует подумать об использовании(...){...} - person Guillaume; 10.11.2009

После того, как вы прочитаете файл до конца и найдёте совпадение (при условии, что у вас есть что-то вроде логического значения, чтобы сообщить, что экспорт произошёл и совпадение было найдено), вы можете проверить свойство EndOfStream в средстве чтения потока и вывести сообщение. Или вы можете просто проверить значение совпадения, чтобы увидеть, вернуло ли оно значение true.

person thismat    schedule 10.11.2009