# Running a file using java code

**URL:** https://forum.codewithmosh.com/t/running-a-file-using-java-code/5466
**Category:** Java
**Created:** [June 12, 2021, 7:35am UTC](https://forum.codewithmosh.com/t/running-a-file-using-java-code/5466 "2021-06-12T07:35:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Intijir](https://avatars.discourse-cdn.com/v4/letter/i/f17d59/32.png) [@Intijir](https://forum.codewithmosh.com/u/Intijir)
#### Post date: [June 12, 2021, 7:35am UTC](https://forum.codewithmosh.com/t/running-a-file-using-java-code/5466/1 "2021-06-12T07:35:45Z")

</div>

Is there a way to run/execute a file such as an exe or a jar file using java code that is located in the directory?

---

<div class="post-metadata">

### Author: ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)
#### Post date: [August 18, 2022, 3:11am UTC](https://forum.codewithmosh.com/t/running-a-file-using-java-code/5466/2 "2022-08-18T03:11:41Z")

</div>

In general, to run any command line:

```java
var process = Runtime.getRuntime().exec(...);

```

You can read more details about the `exec` method to get more details about how to use / run it.
