In my opinion, that function is only useful with a string parameter. What does it do?
- It creates a file object.
- Checks that it can be created.
- Checks that it's a file
- Returns the length
If you passed it a file, the first thing isn't needed, the next two should probably be assumed, and the length is a file member function. If you pass this a file, this function becomes too trivial to write :)
(Also, I think returning null from a function that returns a long is strange)
If you have a File object already, use:
length = file.isFile() ? file.length() : -1;
If your code deals with files instead of file names you could save yourself some file opens if you reuse the File pointers. In that case, it might lead you to use them over the filename approach.