8

I need the filesize on disk and not the file size.

File myFile = new File ("C:\\Send\\Capture.png");
System.out.println((int)myFile.length());

This code gives the file size. I need the file size on disk. They always happen to be different, like in the picture below, right?

enter image description here

EricSchaefer
  • 23,996
  • 21
  • 67
  • 100
GrowinMan
  • 4,821
  • 12
  • 40
  • 58
  • In Java there is nothing to do with hadware or Operating System. You can only find the No. of bytes in a File not in terms of disk space.But using JNI from Java you may find. – Subhrajyoti Majumder Apr 21 '12 at 14:09

1 Answers1

0

Have a look at link

the answer is provided for c# , but since it uses win32 API functions , you can easily convert it to java. the function used to get the size on disk is GetCompressedFileSize

hope that helps

Community
  • 1
  • 1
CyprUS
  • 4,069
  • 8
  • 45
  • 91