Create random test files

Because I want to test the method of comparing files, I randomly store some numbers in the text for testing.

C  # compares whether the contents of two files are the sameicon-default.png?t=LA92

    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();
    }

This creates a random 1KB file, which is kind of fun!

Guess you like

Origin blog.csdn.net/qq_33461689/article/details/121518786
Recommended