/// <summary>
/// 通过文件头来检查文件的类型
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private static bool CheckFileHead(string filePath)
{
var fs = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
var r = new BinaryReader(fs);
string fileclass = "";
try
{
byte buffer = r.ReadByte();
fileclass = buffer.ToString(CultureInfo.InvariantCulture);
buffer = r.ReadByte();
fileclass += buffer.ToString(CultureInfo.InvariantCulture);
}
catch
{
System.IO.File.Delete(filePath);
return false;
}
r.Close();
fs.Close();
bool check = (fileclass == "8075" || fileclass == "208207");
if (!check)
{
System.IO.File.Delete(filePath);
}
return check;
}

相关文章:

  • 2021-12-09
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
猜你喜欢
  • 2021-11-29
  • 2022-01-21
  • 2021-10-09
  • 2022-12-23
  • 2022-02-21
  • 2021-10-13
  • 2021-06-11
相关资源
相似解决方案