/**
* 創建多級目錄文件
*
* @param path 文件路徑
* @throws IOException
*/
private void createFile(String path) throws IOException {
if (StringUtils.isNotEmpty(path)) {
File file = new File(path);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
}
</div>
第二種方法代碼如下:
//路徑
String path = "/usr/sunny/images/product/img/";
File file = new File(path);
//如果路徑不存在,新建
if(!file.exists()&&!file.isDirectory()) {
file.mkdirs();
}