Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class Main { private static final String batchDir = System.getProperty("user.dir") + "\\batch\\"; private static void mergeExeBatchFiles() { File file = new File(batchDir); System.out.println("debug:current path = " + file.getAbsolutePath()); File[] files = file.listFiles(); if (files == null || files.length == 0) { return; } Arrays.sort(files, new Comparator<File>() { public int compare(File file1, File file2) { if (file1.lastModified() > file2.lastModified()) { return 1; } else if (file1.lastModified() < file2.lastModified()) { return -1; } else { return 0; } } }); StringBuffer command = new StringBuffer(); for (File f : files) { command.append("call ").append(f.getAbsolutePath()).append("\n"); } try { String filePath = batchDir + "build.bat"; writeFile(filePath, command.toString()); Runtime.getRuntime().exec("cmd /c start " + filePath); } catch (Exception e) { e.printStackTrace(); } } private static void writeFile(String filePath, String content) throws IOException { FileWriter fw = new FileWriter(filePath); PrintWriter out = new PrintWriter(fw); out.write(content); out.println(); fw.close(); out.close(); } }