java,import java.io.File;,,public class CreateDirectory {, public static void main(String[] args) {, // 指定要创建的目录路径, String directoryPath = "/path/to/directory";, , // 创建File对象, File directory = new File(directoryPath);, , // 检查目录是否已经存在, if (!directory.exists()) {, // 尝试创建目录, if (directory.mkdirs()) {, System.out.println("目录创建成功: " + directoryPath);, } else {, System.out.println("目录创建失败");, }, } else {, System.out.println("目录已存在: " + directoryPath);, }, },},
`,,请将
/path/to/directory`替换为实际的目录路径。运行此程序后,它将在指定路径下创建一个新目录。Powered By Z-BlogPHP 1.7.3