我正在编写一个应该计算熵的小程序,获取有关文件的信息等。但是我遇到的问题实际上应该非常简单。
我无法将文字附加到txt文件,我甚至不知道为什么。我尝试了TextWriter
,StreamWriter
,File.AppendAllText
等等,但没有一个正在运作 - 我不知道为什么。
这是一段代码因为我疯了:
string pathx = Environment.CurrentDirectory + "//confusio.txt";
if (File.Exists(pathx))
{
File.Delete(pathx);
File.Create(pathx);
}
else
{
File.Create(pathx);
}
string all = null;
all += "Confusio log file\n";
all += "Log created: " + DateTime.Now.ToLongDateString();
all += " User: " + Environment.UserName.ToString() + "\n\n\n";
all += "-=*( LOG )*=-\n";
all += ("Full name: " + full + '\n');
all += ("Size: " + size + " (bytes)\n");
all += ("Creation time: " + creation_time + '\n');
all += ("MD5: " + md5 + '\n');
all += ("SHA1: " + sha1 + '\n');
all += ("SHA256: " + sha256 + '\n');
all += ("Entropy: " + ShannonEntropy(buff) + '\n');
all += ("Last Write: " + lastWrite + '\n');
all += ("Last access: " + lastAccess + '\n');
all += ("Is read only: " + isReadOnly + '\n');
Console.Write(all); //for debugging
Console.ReadKey(); //for debugging
TextWriter twrt = new StreamWriter(@pathx, true);
twrt.Write(all);
twrt.Close();
Console.WriteLine("Log file created at: " + pathx);
Console.ReadKey();