/// 生成为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;
}
生成n个Txt文件
最新推荐文章于 2022-05-30 18:08:11 发布