生成n个Txt文件

来源:互联网 发布:围棋中的算法 编辑:程序博客网 时间:2024/04/29 07:39
        /// 生成为txt格式的文件。        /// </summary>        /// <param name="strtext">要保存的字符串内容。</param>        private int CreateAsTxtFile(object strtext)        {            int all = 0;            for (int fileNum = 0; fileNum < 3; fileNum++)            {                string path = @"d:\creFiles\";                DirectoryInfo chePath = new DirectoryInfo(path);                if (!chePath.Exists)                    chePath.Create();                Random ran = new Random();                int fileSiz = ran.Next(5550);                FileStream fs1 = new FileStream(path + fileNum + ".txt", FileMode.Create, FileAccess.Write);//创建写入文件                  StreamWriter sw = new StreamWriter(fs1);                for (int i = 0; i < fileSiz; i++)                {                    sw.Write(strtext);//开始写入值                    sw.Write(strtext.ToString());                }                sw.Close();                fs1.Close();            }            return all;        }

0 0