java's method for determining binaries

  • 2020-10-23 20:57:08
  • OfStack

java method for judging base 2 files

Code directly, the implementation method is simple:

Code implementation:


public static boolean isBinary(File file)  
 
{ 
boolean isBinary = false; 
try { 
FileInputStream fin = new FileInputStream(file); 
long len = file.length();  
 for (int j = 0; j < (int) len; j++) { 
int t = fin.read(); 
if (t < 32 && t != 9 && t != 10 && t != 13) { 
isBinary = true; 
break; 
} 
} 
} catch (Exception e) { 
e.printStackTrace(); 
} 
return isBinary; 
} 

If you have any questions, please leave a message or go to this site community exchange discussion, thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: