SoFunction
Updated on 2025-03-07

C# shared state file read and write implementation code


using ;
using ;
namespace
{
public static class FileHelper
{
public static string ShareRead(string file, Encoding encoding)
{
string content = ;
FileStream fs = new FileStream(file, , , );
try
{
if ()
{
byte[] buffer = new byte[];
(buffer, 0, );
content = (buffer);
}
}
finally
{
();
();
}
return content;
}
public static void ShareAppend(string content, string file, Encoding encoding)
{
ShareWrite(content, file, encoding, );
}
public static void ShareWrite(string content, string file, Encoding encoding, FileMode fileMode)
{
FileStream fs = new FileStream(file, fileMode, , );
try
{
if ()
{
byte[] buffer = (content);
if ( > 0)
{
(buffer, 0, );
();
}
}
}
finally
{
();
();
}
}
}
}