首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StreamReader C#

StreamReader C#
EN

Stack Overflow用户
提问于 2009-11-10 22:05:07
回答 4查看 3.8K关注 0票数 0

在使用C#中的streamReader函数读取文本文件(其中包含要导出到数据库的文件的位置)时,如何向将显示在命令提示符窗口(控制台应用程序)中的代码添加确认消息,以便我知道文件已读取并已导出?

代码语言:javascript
复制
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()));
        }
    }
EN

回答 4

Stack Overflow用户

发布于 2009-11-10 22:07:02

添加以下内容:

代码语言:javascript
复制
Console.WriteLine("Done reading & Exporting");

上图

代码语言:javascript
复制
}
catch (Exception e)
{
票数 9
EN

Stack Overflow用户

发布于 2009-11-10 22:15:31

不要忘记Console.ReadKey(),以防您想要在上面实际看到它

票数 1
EN

Stack Overflow用户

发布于 2009-11-10 22:07:29

在writer对象上使用flush,然后关闭。

然后将done写入控制台。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1708203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档