Пример #1
0
        public void output(string path, int n)
        {
            Read             read            = new Read();
            string           str             = read.Read1(path);
            ICountCharacters countcharacters = new CountCharacters();
            ValidLine        validline       = new ValidLine();
            ICountWords      countwords      = new CountWords();
            ITopWords        toptenwords     = new TopWords();
            bool             a = false;

            Console.WriteLine("是否输出以上数据至output.txt(是请输入Y,否则输入N)");
            char b = 'N';

            b = Convert.ToChar(Console.ReadLine());
            if (b == 'Y')
            {
                a = true;
            }
            if (a)
            {
                string       FileName = @"C: \Users\24554\Desktop\第三次作业\201731062117\wordCount\output.txt";
                StreamWriter sw       = new StreamWriter(FileName);
                sw.WriteLine("\n\ncharacters:" + countcharacters.Countcharacters(str));
                sw.WriteLine("validline:" + validline.ValidLine1(path));
                sw.WriteLine("countwords:" + countwords.Countwords(str));
                sw.WriteLine("toptenwords:\n\n" + toptenwords.Topnwords(countwords.Getwords(str), n));
                Console.WriteLine("保存成功!!!");
                sw.Close();
            }
        }
Пример #2
0
        public void output(string path, int n)
        {
            Read             read            = new Read();
            string           str             = read.Read1(path);
            ICountCharacters countcharacters = new CountCharacters();
            ValidLine        validline       = new ValidLine();
            ICountWords      countwords      = new CountWords();
            ITopWords        toptenwords     = new TopWords();
            bool             a = false;

            Console.WriteLine("是否输出以上数据至output.txt(是请输入Y,否则输入N)");
            char b = 'N';

            b = Convert.ToChar(Console.ReadLine());
            if (b == 'Y')
            {
                a = true;
            }
            if (a)
            {
                string FileName = @"D:\output.txt";
                //FileStream fs = new FileStream("D:\\wordCount\\wordCount\\wordCount\\bin\\Debug\\123.txt", FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(FileName);
                sw.WriteLine("\n\ncharacters:" + countcharacters.Countcharacters(str));
                sw.WriteLine("validline:" + validline.ValidLine1(path));
                sw.WriteLine("countwords:" + countwords.Countwords(str));
                sw.WriteLine("toptenwords:\n\n" + toptenwords.Topnwords(countwords.Getwords(str), n));
                Console.WriteLine("保存成功,可前往D盘查看!");
                sw.Close();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            string str  = null;
            string path = null;
            int    n;

            if (args.Length != 0)
            {
                path = args[0];
            }
            if (path == null)
            {
                Console.WriteLine("请输入文件路径:");
                path = Console.ReadLine();
            }
            Read read = new Read();

            while (true)
            {
                //异常处理文件路径输错的情况
                try
                {
                    str = read.Read1(path);
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message.ToString());
                    Console.WriteLine("\n请重新输入文件路径:");
                    path = Console.ReadLine();
                }
            }
            ICountCharacters countcharacters = new CountCharacters();
            ValidLine        validline       = new ValidLine();
            ICountWords      countwords      = new CountWords();
            ITopWords        toptenwords     = new TopWords();

            Console.WriteLine("\n\ncharacters:" + countcharacters.Countcharacters(str));
            Console.WriteLine("\nvalidline:" + validline.ValidLine1(path));
            Console.WriteLine("\ncountwords:" + countwords.Countwords(str));
            Console.WriteLine("\n输入需要显示的前多少个单词 n :");
            n = Int32.Parse(Console.ReadLine());
            Console.WriteLine("\ntoptenwords:\n\n" + toptenwords.Topnwords(countwords.Getwords(str), n));
            Output output = new Output();

            output.output(path, n);
        }