Java method to determine whether a file is binary
- 2020-04-01 04:03:33
- OfStack
This article illustrates a Java method for determining whether a file is binary or not. Share with you for your reference. The details are as follows:
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;
}
I hope this article has been helpful to your Java programming.