Get the latest tech news
How to Use the Foreign Function API in Java 22 to Call C Libraries
Using Java's Foreign Function API to Call C like fopen, fgets, and fclose.
Using the FFM API to call regular functions that already exist in the Java standard library makes no sense because there will always be an overhead. The code finds the address (pointer) of where fopen is stored, and returns it, or throws an exception if it wasn’t found. It’s like a java flavoured version of how you read a file in plain C. The buffer.getString returns the string stored in the buffer at offset 0.
Or read this on Hacker News