If I am tring to open notepad from Java Application then it will open Notepad.But If I will try to open Excel then it is giving me exception.
try
{
Runtime.getRuntime().exec("excel");
}
catch (IOException e)
{
e.printStackTrace();
}
Following is Exception :
java.io.IOException: Cannot run program "excel": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at OpenNotepad.main(OpenNotepad.java:18)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
When I do start->Run->Excel then it will open excel.
If you are trying to use Java to open an Excel file, rather than just opening Excel, I suggest you use the Desktop API class: http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html
This class will use the default OS file handling mechanism, so it will use say MS Excel in Windows, and Open Office in Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With