//if (!File.Exists(newfilepath + "\\" + name + num + ".txt"))
            //{
            //    File.Create(newfilepath + "\\" + name + num + ".txt");
            //}
            string hang;
            StreamWriter sw = new StreamWriter(newfilepath + "\\" + name + num + ".txt", true, System.Text.Encoding.GetEncoding("UTF-8"));

从网上找了段代码 整理了下. 原先是新建文件夹的代码. 让我改成了文件的方式,结果是多此一举, StreamWriter 方法在文件不存在的时候,会自动创建,不需要先创建空文件,注释掉上边的file之后问题解决.

posted on 2018-04-23 10:06  小石头的一天  阅读(373)  评论(0编辑  收藏  举报