private native String nativeOpenOffline(String filename);
用native关键字就可以实现调用c的函数。
Native methods :Native indicates that a method is written in a platform-dependent language to perform a platform specific function that cannot be handled in Java. You will not need to know how to use native methods for the exam, other than knowing that native is a reserved keyword.
用native关键字就可以实现调用c的函数。
Native methods :Native indicates that a method is written in a platform-dependent language to perform a platform specific function that cannot be handled in Java. You will not need to know how to use native methods for the exam, other than knowing that native is a reserved keyword.
示例:
class try{
public static void main(String args[]){
try{
Runtime.getRuntime().exec("cmd /c start ***.exe");
}
catch (Exception e){
System.out.println("the call .exe file failed!");
}
}
}
superLee(superLee)
根据情况,来定
文件一 HelloNative.java
class HelloNative
{ public static native void greeting();
static
{ System.loadLibrary("DllTest");
// 此处DllTest是一个动态链接库DllTest.dll
}
}
// 编译成.class 然后用 dos 命令 javah HelloNative,生成HelloNative.h头文件
内容如下
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloNative */#ifndef _Included_HelloNative
#define _Included_HelloNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloNative
* Method: greeting
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloNative_greeting
(JNIEnv *, jclass);#ifdef __cplusplus
}
#endif
#endif
----------------------------
之后,用C实现方法
JNIEXPORT void JNICALL Java_HelloNative_greeting
(JNIEnv* env, jclass cl)
{ ............... }
并将它生成DllTest.dll
ok了