Getting the Size of a File

File file = new File("infilename");

// Get the number of bytes in the file
long length = file.length();

Comments

4 Feb 2010 - 12:52pm by Anonymous (not verified)

Simple and perfect!

1 Dec 2010 - 8:36am by Anonymous (not verified)

Short, sweet, precise, and just what I needed. Thanks.

28 Dec 2010 - 5:36am by Anonymous (not verified)

great!!!

16 Mar 2011 - 12:26pm by Anonymous (not verified)

This is so awesome. I have searched everywhere and I didn't find it anywhere. This is so awesome. Short and sweet. Just the thing I am looking for.

10 Apr 2011 - 3:17pm by business loans (not verified)

People deserve very good life and business loans or just consolidation loan can make it much better. Just because freedom bases on money.

17 May 2011 - 12:44am by Anonymous (not verified)

Thx 4 this solution

17 May 2011 - 12:59pm by Anonymous (not verified)

Every time I go to get the size of a file, I always put file.getSize(), then it doesn't compile. I google it, and it comes up here to remind me it's .length() instead :-)

17 May 2011 - 1:00pm by Anonymous (not verified)

Every time I go to get the size of a file, I always put file.getSize(), then it doesn't compile. I google it, and it comes up here to remind me it's .length() instead :-)

17 Aug 2011 - 3:31am by Naeem Ahmad (not verified)

Perfect and Awesome

25 Oct 2011 - 2:02am by Santa (not verified)

Ho-Ho-Ho!

17 Nov 2011 - 1:17am by Anonymous (not verified)

This returns me 3 even though the file doesn't contain any characters... any idea why?

13 Dec 2011 - 2:06am by Anonymous (not verified)

getting the size of file

30 Jan 2012 - 4:29pm by Anonymous (not verified)

doesn't work correctly in windows

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.