public class LoadWinApp
{
public static void main(String args[]) throws IOException
{
Runtime r = Runtime.getRuntime();
Process p = null;
String strWinApp = "cmd.exe start ";
String strWinFile = "D:\\test.doc"; if(args.length > 0)
{
strWinFile = args[0];
}
try
{
p = r.exec(strWinApp + " " + strWinFile);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}先获取文件的路径名, 再把其中所有的 \ 换成 \\ 就可以啦。
用StringTokenizer s = new StringTokenizer (path,"\\");
{
public static void main(String args[]) throws IOException
{
Runtime r = Runtime.getRuntime();
Process p = null;
String strWinApp = "cmd.exe start ";
String strWinFile = "D:\\test.doc"; if(args.length > 0)
{
strWinFile = args[0];
}
try
{
p = r.exec(strWinApp + " " + strWinFile);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}先获取文件的路径名, 再把其中所有的 \ 换成 \\ 就可以啦。
用StringTokenizer s = new StringTokenizer (path,"\\");
http://expert.csdn.net/Expert/topic/2231/2231433.xmlTO:cans(cans)
你用了cmd.exe start还真是个不错的方法,省了主文件的定位
如果后者,可以这样
Runtime r = Runtime.getRuntime();
Process p = r.exec("cmd.exe /c start a.doc");
p.waitFor();