-4

Is there any way to determine a file's size without having to open it, as provided in the Java platform API (no 3rd party libs)? Also, I need the 64-bit size (which I assume Java would provide to begin with).

skaffman
  • 390,936
  • 96
  • 800
  • 764
Spliff
  • 351
  • 1
  • 3
  • 6

3 Answers3

3

Yes, calling .length() on a File Object will return its size in bytes.

Bohemian
  • 389,931
  • 88
  • 552
  • 692
Sahil Muthoo
  • 11,313
  • 2
  • 28
  • 37
0

long File.length(). A File object usually represents a path, rather than an open file.

Vlad
  • 17,655
  • 4
  • 40
  • 70
0

Without constructing any object for a particular file,How can you use the properties of file class. OPEN a file means that you are decoding the file data in your compatible format(.txt/.bmp/.pdf etc). SO you have to first

File file=new File("File Name");

File Name-->file name of file to which you want to deal. Then use file.length();

In this phenomenon you are not opening any file,you are just passing reference(address) of the file and retrieving its size. thats it. i hope this will beneficial to you.

SilentBomb
  • 168
  • 2
  • 11