I found that Windows’ ShellExecute (in the Win32 API) could be very useful, especially in the noddy VB6 applications I keep being asked to write.
Anyway, I was looking at doing something similar in Java.
This only works in Windows – but basically, you rely on the Windows performing it’s default action…
import java.lang.*;
public class OpenDocument {
public static void main (String [] Args ) {
System.out.println("Main:");
Process oProcess;
String cmd[] = { "cmd" , "/c", "start" , "C:\Java\OpenDocument\Hamlet.doc"};
try {
oProcess = Runtime.getRuntime().exec( cmd );
} catch ( Exception e ) {
System.out.println(e.toString());
}
}
}
In this case, the programme ‘starts’ a word document – that is, it opens up Word and loads in the document. This is done via the command prompt. Nuff said.