Is there a Java equivalent of GetCompressedFileSize?

前端 未结 3 1916
一个人的身影
一个人的身影 2021-01-22 19:17

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

3条回答
  •  梦谈多话
    2021-01-22 19:37

    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);
    }
    

提交回复
热议问题