public class FileDir { /** * @param args * @author Ben Zeph */ public static void filedir() { File root = new File("D://root dir"); File[] dirs = new File[3]; File[] files = new File[3]; if (!root.exists()) root.mkdir(); for (int i = 0; i <= 2; i++) { dirs[i] = new File(root, "dir" + String.valueOf(i)); dirs[i].mkdir(); files[i] = new File(dirs[i], "file" + String.valueOf(i) + ".txt"); try { files[i].createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("目录和文件创建完成"); } public static void main(String[] args) { // TODO Auto-generated method stub FileDir.filedir(); } }