Take the tour ×  Is there any way to access the number of blocks
allocated to a file with the standard Java File API? Or even do
it with some unsupported & undocumented API underneat. Anything
to avoid native code plugins.  I'm talking about the st_blocks
field of struct stat that the fstat/stat syscalls work on in
Unix.  What I want to do is to create a sparse copy of a file
that now has lots of redundant data, i.e. make a new copy of it,
only containing the active data but sparsely written to it. Then
swap the two files with an atomic rename/link operation. But I
need a way to find out how many blocks are allocated to the file
beforehand, it might already have been sparsely copied. The old
file is then removed.  This will be used to free up disk space
in a database application that is 100% Java. The benefit on
relying on sparse file support in the filesystem is that I would
not have to change the index that point out the location where
the data is, that increases the complexity of the task at hand.
I think