System.out stdout Is there another fundamental problem that you are facing (maybe mixing output?).
Since the other member also mentioned the last point - I have to explain further:
System.out and stdout both correspond to file descriptor # 1.
However, the Java libraries OutputStream (and derived classes) and C stdio have their own (independent) buffering mechanisms to reduce the number of calls to the base write system call. Just because you called printf or the like does not guarantee that your output will appear immediately.
Since these buffering methods are independent, output from Java code may (theoretically) be confused or otherwise out of order with respect to output from C.
If this is a concern, you should arrange to call System.out.flush() before calling the JNI function and in your C function (if it uses stdio rather than a low level write call), you should call fflush(stdout) before returning.
source share