admin管理员组文章数量:1516870
public int GetFileType(string filePath)
{
int result = 0;
if (File.Exists(filePath) == false)
{
return 0;
}
try
{
FileStream fs = new FileStream(filePath, FileMode.Open);
int byteA = fs.ReadByte(); //byte[0]
int byteB = fs.ReadByte(); //byte[1]
fs.ReadByte(); //byte[2]
int byteC = fs.ReadByte(); //byte[3]
int byteD = fs.ReadByte(); //byte[4]
fs.Close();
fs.Dispose();
//ZIP:1
if (byteA == 80 && byteB == 75)
{
result = 1;
}
//LZH:2
else if (byteC == 108 && byteD == 104)
{
result = 2;
}
//TGZ:3
else if (byteA == 31 && byteB == 139)
{
result = 3;
}
//UNKNOWN:0
else
{
result = 0;
}
}
catch
{
return 0;
}
return result;
}版权声明:本文标题:Linux世界中的C++秘籍:快速判断非压缩文件 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/biancheng/1771435453a3265496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论