1。Process process1 = Runtime.getRuntime().exec("cmd /c copy c:\\a.doc d:\\b.doc"); 
2。Process process2 = Runtime.getRuntime().exec("start d:\\b.doc"); 
运行总是发生错误,说没有b.doc文件,原因可能是1需要较长的时间,而2急着要运行,所以发生错误。改成如下,程序就死了。
1。Process process1 = Runtime.getRuntime().exec("cmd /c copy c:\\a.doc d:\\b.doc"); 
   process1.waitFor();
2。Process process2 = Runtime.getRuntime().exec("start d:\\b.doc"); 
   process2.waitFor();

解决方案 »

  1.   

    你的目的是什么,第一句是想把a.doc里面的内容复制到b.doc,然后打开b.doc这个文档吗??
    如果是:那下面的代码可以实现
    public class tt
    {
    public static void main(String args[])
    {
    try
    {

    Process process1 = Runtime.getRuntime().exec("cmd /c start copy c:\\c.doc d:\\a.doc"); 
    Process process2 = Runtime.getRuntime().exec("cmd /c start d:\\a.doc"); 
    }
    catch(Exception e){System.out.println ("fdsfsd");}
    }}
      

  2.   

    如果你是想打开二个WORD文档,这些代码可以实现:
    public class tt
    {
    public static void main(String args[])
    {
    try
    {

    Process process1 = Runtime.getRuntime().exec("cmd /c start c:\\c.doc"); 
    Process process2 = Runtime.getRuntime().exec("cmd /c start d:\\a.doc"); 
    }
    catch(Exception e){System.out.println ("fdsfsd");}
    }}二条代码我都运行通过.给分吧100分
      

  3.   

    deweyroy(马涛) :你的代码和楼主的没有什么区别,当文件够大时一样会出错
      

  4.   

    可能要加上thread.join()这样的代码,就可以了,当然如何加是个问题!!
      

  5.   

    不需要  process2.waitFor();
    我的就不会死
      

  6.   

    当文件比较大时,出错!
    也就是复制命令还没执行完,打开操作就要进行,当然出错了。
    加上waitfor也不行。
      

  7.   

    你试试这个:
    import java.util.*;
    import java.io.*;
    /**
     * @author Administrator
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class recursion 
    {

    public static void main(String[] args) throws IOException , InterruptedException 
    {
    Process process1,process2; 

    process1 = Runtime.getRuntime().exec("cmd /c copy c:\\a.txt d:\\b.txt"); 
        //process1.waitFor();
       
        if (process1.waitFor() == 0)

    process2 = Runtime.getRuntime().exec("cmd /c d:\\b.txt");
    }
    }