Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:51:09+00:00 2026-05-27T09:51:09+00:00

I am trying to convert a jbyteArray to native c string (char*) in jni?

  • 0

I am trying to convert a jbyteArray to native c string (char*) in jni? Unfortunately I can’t find any documentation on how to do that. I’m invoking a java function with the following prototype in the c code.

public static byte[] processFile(byte[] p_fileContent)

In the c code I am invoking this function which is returning a byte array. The content of this byte array is a java string. But I need to convert it to a c string.

jbyteArray arr = (jbyteArray) env->CallObjectMethod(clsH, midMain, jb);
printf("%s\n", (char*) arr);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:51:10+00:00Added an answer on May 27, 2026 at 9:51 am

    I believe you would use GetByteArrayElements and ReleaseByteArrayElements. Something like:

    boolean isCopy;
    jbyte* b = GetByteArrayElements(env, arr, &isCopy);
    

    You should be able to cast b to char* at this point in order to access the data in the array. Note that this may create a copy of the data, so you’ll want to make sure to release the memory using ReleaseByteArrayElements:

    ReleaseByteArrayElements(env, arr, b, 0);
    

    The last parameter is a mode indicating how changes to b should be handled. 0 indicates that the values are copied back to arr. If you don’t want to copy the data back to arr, use JNI_ABORT instead.

    For more details see the JNI Reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am trying convert string to float,when i am passing single char it is giving
Trying to convert the following but am having difficulty. Can anyone see where I'm
Trying to convert int arrays to string arrays in numpy In [66]: a=array([0,33,4444522]) In
How to extract and save array from string parameter? I'm trying convert string beafore_create
Trying to convert a string to NSURL and this is not happening. barcodeTextLabel.text =
im trying to convert a json object to a string by using gson here
So I'm essentially trying to implement an AIR Native Extension that does the physics
I'm trying to request a webpage using WebRequest.GetResponse(); and convert that response to a
Trying to convert a JSON string into an object in C#. Using a really
Trying to convert this 0.274509817 to a nice precentage like 27% The string is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.