比如我的程序在的d:\test目录下,我想使该程序运行在e:\下,但又不移动程序,应该怎么做呢?也就是说怎么样使程序先进入到指定目录下。 例如在程序里用来类似dos里的dir命令,显示的是别的文件夹的文件列表,或者这样说,我想让程序先进入预定的目录然后再运行程序的主体。 请问程序应该怎么写呢?

解决方案 »

  1.   

    such as:
    public class delTest{ 
      public static void main (String[] args) throws  IOException,InterruptedException { 
       System.out.println("test");
        Runtime runtime = Runtime.getRuntime(); 
        Process process = runtime.exec("cmd.exe /c del F:\\12.txt");
        System.out.println("del success");
        process.waitFor();
      } 
      

  2.   

    可不可以像dos的命令一样先进入F盘,在执行del 12.txt命令呢?