Possible Duplicate:
Size of folder or file
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()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
length()method in theFileclass. From the javadocs:UPDATED Nowadays we should use the
Files.size()method: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 pathnamegetTotalSpace()Returns the size of the partition named by this abstract pathnamegetFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name