Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Using system. IO;
Namespace myquery. utils
{
/// <Summary>
/// Encapsulate Binary File Processing
/// By Jia Shiyi 2011-8-21
/// </Summary>
Public static class filehelper
{
/// <Summary>
/// Obtain file data
/// </Summary>
/// <Param name = "FILENAME"> complete path file name </param>
/// <Returns> </returns>
Public static byte [] getcontent (string filename)
{
Byte [] result = NULL;
If (file. exists (filename ))
{
Filestream FS = new filestream (filename, filemode. Open );
Result = new byte [fs. Length];
Int offset = 0;
While (offset <fs. length)
{
Int COUNT = 1024;
If (FS. Length <OFFSET + count)
{
Count = convert. toint32 (FS. Length-offset );
}
FS. Read (result, offset, count );
Offset + = count;
}
FS. Close ();
}
Return result;
}
/// <Summary>
/// Write content to a file
/// </Summary>
/// <Param name = "name"> complete file name </param>
/// <Param name = "content"> content </param>
/// <Param name = "iscover"> whether to overwrite existing files </param>
Public static void writetofile (string name, byte [] content, bool iscover)
{
Filestream FS = NULL;
Try
{
If (! Iscover & file. exists (name ))
{
FS = new filestream (name, filemode. append, fileaccess. Write );
}
Else
{
FS = new filestream (name, filemode. Create, fileaccess. Write );
}
Binarywriter BR = new binarywriter (FS );
BR. Write (content );
BR. Flush ();
BR. Close ();
}
Finally
{
If (FS! = NULL)
{
FS. Close ();
}
}
}
}
}
Welcome to: http: // 121.18.78.216, which is a demonstration platform for ease of query and analysis, workflow, content management, and project management.