/**
* example-01: GetStringUTFChars()
*
* 代码出自《The Java Native Interface Programmer’s Guide and Specification》
* 运行平台:Windows XP
*/
/**
* The example program, Prompt.java , contains a
* native method that prints a string, waits for user input, and then returns the line
* that the user has typed in.
*/
// Prompt.java
public class Prompt
{
// native method that prints a prompt and reads a line
private native String getLine(String prompt);
public static void main(String args[])
{
Prompt p = new Prompt();
String temp = new String("Type a line: ");
String input = p.getLine(temp);
System.out.println("User typed: " + input);
System.out.println(temp);
}
static
{
System.loadLibrary("Prompt");
}
}
/* command
javac Prompt.java
javah Prompt
get a file: Prompt.h
*/
#include "Prompt.h"
#include <stdio.h>
#include <string.h>
JNIEXPORT jstring JNICALL Java_Prompt_
JNI: Get/ReleaseStringUTFChars和Get/ReleaseIntArrayElements的区别,isCopy是否重新分配内存的问题
最新推荐文章于 2023-09-12 09:28:55 发布