我不知道这是否可能,但有没有办法使用 JNI(Java 本地接口)使用 .java 文件调用 .c 文件的主要功能?例如
伪代码:
/*This is the .c file*/
int main(int argc, char* argv[]){
File pFile;
pFile = fopen(argv[1],"r"]);
fclose(argv[1]);
}
再次伪代码:
/*This is the .java file*/
public class maincpy{
static
{
System.loadLibrary("maincpy");
}
public native int maincpy(int argc, char* argv[]); //
public static void main(String[] args){
maincpy c = new maincpy();
c.main(2,"somefile.txt");
}
}
我知道我所写的内容不正确,因为使用 char* argv[] 作为本机函数的参数时出现错误。但我希望这能让我明白我想做的事情。任何帮助,将不胜感激。