try {
File f=new File("D:\\testbat.txt");
String str="@echo off\r\necho helloword\r\nnotepad d:\\jieyaTest2.java\r\nexit";
File f2=new File("D:\\battest.bat");
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeBytes(str);
dos.flush();
dos.close();
fos.close();
f.renameTo(f2);
Process pro=Runtime.getRuntime().exec("cmd.exe /c start "+f2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这么一个类 我运行后dos窗口老是显示如何让它消失应该加上什么代码

解决方案 »

  1.   

    加上下面这个试试:
    pro.destroy();
    用这个也可以
    org.eclipse.swt.program.Program.launch("a.bat");
      

  2.   

    谢谢可是你这样我的记事本就根本没有执行啊 我的意思是让先让dos显示一下然后关闭
      

  3.   

    可以试用javaw命令代替java命令运行你的程序,就不会dos界面了。
    The javaw.exe command is identical to java.exe, except that with javaw.exe there is no associated console window. This implies you can't get it to display the version with -version since there is no console to display it on. Use javaw.exe when you don't want a command prompt window to appear. The javaw.exe launcher will, however, display a dialog box with error information if a launch fails for some reason.
      

  4.   

    怎么用javaw命令 本人新手不懂 我用的是eclipse编译没有javaw命令啊