c++调用java内部类加$

要模仿的java方法如下:

    private static MappedByteBuffer loadModelFile()
            throws IOException {
        @SuppressLint("SdCardPath") File file = new File("/sdcard/libs/data.txt");
        FileInputStream inputStream = new FileInputStream(file);
        FileChannel fileChannel = inputStream.getChannel();
        return fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
    }

里面的MapMode是FileChannel的内部类


jobject get_byte_buffer(JNIEnv *pEnv) {
    //new file
    jclass jc_file = pEnv->FindClass("java/io/File");
    jmethodID file_init = pEnv->GetMethodID(jc_file, "<init>", "(Ljava/lang/String;)V");
    jobject file = pEnv->NewObject(jc_file, file_init, pEnv->NewStringUTF("/sdcard/libs/data.txt"));
    //new FileInputStream
    jclass jc_fileInputStream = pEnv->FindClass("java/io/FileInputStream");
    jmethodID fileInputStream_init = pEnv->GetMethodID(jc_fileInputStream, "<init>", "(Ljava/io/File;)V");
    jobject fileInputStream = pEnv->NewObject(jc_fileInputStream, fileInputStream_init, file);
    // get FileChannel
    jmethodID jm_getChannel = pEnv->GetMethodID(jc_fileInputStream, "getChannel", "()Ljava/nio/channels/FileChannel;");
    jobject fileChannel = pEnv->CallObjectMethod(fileInputStream, jm_getChannel);
    //read_only 马丹谷歌,这样是对的你报鸡巴错
    jclass jc_read_only = pEnv->FindClass("java/nio/channels/FileChannel$MapMode");
    jfieldID jf_read_only = pEnv->GetStaticFieldID(jc_read_only, "READ_ONLY", "Ljava/nio/channels/FileChannel$MapMode;");
    jobject read_only = pEnv->GetStaticObjectField(jc_read_only, jf_read_only);
    //file length
    jmethodID jm_length = pEnv->GetMethodID(jc_file, "length", "()J");
    jlong length = pEnv->CallLongMethod(file, jm_length);
    jlong position = 0;
    //map result
    jclass jc_fileChannel = pEnv->FindClass("java/nio/channels/FileChannel");
    jmethodID jm_map = pEnv->GetMethodID(jc_fileChannel, "map",
                                         "(Ljava/nio/channels/FileChannel$MapMode;JJ)Ljava/nio/MappedByteBuffer;");
    if (jm_map == nullptr){
        LOGE("map 方法未找到")
    }
    jobject result = pEnv->CallObjectMethod(fileChannel, jm_map, read_only, position, length);
    return result;
}

特么的浪费我两天时间,谷歌的Androidstudio报错,快捷修改会将参数或者返回的“$”改成“/”。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值