I used this code to instantiate a File object:
File f = new File(path);
How do I get the size of this file?
What is the difference between getUsableSpace(), getTotalSpace(), and getFreeSpace()?
解决方案
Use the length() method in the File class. From the javadocs:
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
For the second part of the question, straight from File's javadocs:
getUsableSpace() Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname
getTotalSpace() Returns the size of the partition named by this abstract pathname
getFreeSpace() Returns the number of unallocated bytes in the partition named by this abstract path name