javaruntime.exec

how to open a file using exec method in java?


C:\Users\Admin\Downloads\VID_20160226_203631957.mp4

when I execute above line in command prompt the corresponding video gets played with default media player.

But when I try to do same using java Runtime class it doesnt work. I am using following method.

Runtime r= Runtime.getRuntime();
r.exec("C:\Users\Admin\Downloads\VID_20160226_203631957.mp4")

Solution

  • Try this.

    Runtime r= Runtime.getRuntime();
    r.exec("cmd /c C:\\Users\\Admin\\Downloads\\VID_20160226_203631957.mp4");