Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute binary files in java?

Tags:

java

binaries

I have a list of binaries written in Java, Ada, C, and Python and I want to execute them. How can I do that? Are there any JVM binding to those languages?

like image 309
Dimitri Avatar asked May 04 '10 13:05

Dimitri


People also ask

Can you run a binary file?

Open File Manager and navigate to the directory containing the program file (a shell script or a binary program file). Right-click on the file and click Properties. Click the Permissions tab. Select the Allow executing file as program option.

How does Java handle binary data?

A binary literal is a number that is represented in 0s and 1s (binary digits). Java allows you to express integral types (byte, short, int, and long) in a binary number system. To specify a binary literal, add the prefix 0b or 0B to the integral value.

What is binary file in Java?

Java binary files are platform independent. They can be interpreted by any computer that supports Java. A stream is a device for transmitting or retrieving 8-bit or byte values. The emphasis is on the action of reading or writing as opposed to the data itself.

Is a binary file an executable?

Binary executable files contain executable code that is represented in specific processor instructions. These instructions are executed by a processor directly. A binary file, however, can have text strings (ASCII and/or Unicode). Most of operating system files are binary files.


2 Answers

If all you want to do is execute existing applictions, you can use the exec methods from the java.io.runtime namespace.

Runtime rt = Runtime.getRuntime();
Process ps = rt.exec("path to my executable.exe");
like image 108
Oded Avatar answered Nov 06 '22 17:11

Oded


If you want to interact with the binary API's, use:

  • Java Native Access (JNA): for loading and calling DLLs.
  • Java Native Interface (JNI): for wrapping a C library in Java.
like image 44
Frederik Avatar answered Nov 06 '22 15:11

Frederik