I am looking to get accurate (i.e. the real size on disk and not the normal size that includes all the 0\'s) measurements of sparse files in Java.
In C++ on Windows one
If you are doing it on Windows alone, you can write it with Java Native Interface
class NativeInterface{
public static native long GetCompressedFileSize(String filename);
}
and in C/C++ file:
extern "C"
JNIEXPORT jlong JNICALL Java_NativeInterface_GetCompressedFileSize
(JNIEnv *env, jobject obj, jstring javaString)
{
const char *nativeString = env->GetStringUTFChars(javaString, 0);
char buffer[512];
strcpy(buffer, nativeString);
env->ReleaseStringUTFChars(javaString, nativeString);
return (jlong) GetCompressedFileSize(buffer, NULL);
}