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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of libraries

libraries

Photo of foreign function api

foreign function api

Related news:

News photo

Rare editions of Pushkin are vanishing from libraries around Europe

News photo

Power of Libraries

News photo

Web Game Engines and Libraries