创建随机的测试文档

因为我想测试比较文件的方法,所以随机了一些数字存到文本里面进行测试。

 C#比较两个文件内容是否相同icon-default.png?t=LA92https://blog.csdn.net/qq_33461689/article/details/121499130?spm=1001.2014.3001.5501

    int _writeLength = 1024;
    string _testPath = @"F:\测试文档.txt";
    private void WriteText()
    {
        StringBuilder stringBuilder = new StringBuilder();
        System.Random _ran = new System.Random();
        for (int i = 0; i < _writeLength; i++)
        {
            stringBuilder.Append(_ran.Next(0, 10));
        }
        FileStream fs = new FileStream(_testPath, FileMode.Create);
        byte[] data = new UTF8Encoding().GetBytes(stringBuilder.ToString());
        fs.Write(data,0,data.Length);
        fs.Flush();
        fs.Close();
    }

这样就创建了一个1KB的随机文件,还挺好玩!

猜你喜欢

转载自blog.csdn.net/qq_33461689/article/details/121518786