package com.hspedu.io_; import org.junit.Test; import java.io.File; import java.io.IOException; public class TestCreateFile { /** * 创建文件夹目录、创建文件 * @throws IOException */ @Test public void createFile() throws IOException { String directoryPath = "e:\\JavaIO\\CreateFile\\"; File directoryFile = new File(directoryPath); String fileName = "createNewFile.txt"; File file = new File(directoryPath, fileName); if (!directoryFile.exists()) { directoryFile.mkdirs(); } file.createNewFile(); } }
注意:文件目录也应该看作是一个文件File对象