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 same
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!