You would do import com.starbase.util.FileUtils;
or import static com.starbase.util.FileUtils.*
. The hierarchy is just showing that the class FileUtils
extends Object
(as do all classes).
You do also have to have the .jar file/API to access this class.
EDIT: Added possible standalone implementation:
If you want to implement this yourself (I noticed your own 'trivial' answer), you could do something like this:
public static boolean isBinary(String fileName) throws IOException {
return isBinary(new File(fileName));
}
public static boolean isBinary(File file) throws IOException {
InputStream is = new FileInputStream(file);
try {
byte[] buf = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buf)) >= 0)
{
for (int i = 0; i < bytesRead; i++) {
if (buf[i] == (byte) 0)
return true;
}
}
return false;
} finally {
is.close();
}
}
Please note, I have not tested this.
I should add that this is the trivial implementation. There are many kinds of text files that would be considered binary with this. If you were to allow text to be Unicode and/or UTF-8 (or other text encoding) then this quickly becomes very difficult. Then you need to develop some kinds of heuristics to differentiate between the kinds of files and this would not be 100% accurate. So, it really depends on what you are trying to do with this.