All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.niuable.utils.FileKit Maven / Gradle / Ivy

package cn.niuable.utils;

import java.io.File;
import java.io.IOException;

/**
 * 文件创建
 * @author 王维
 * 
 * www.51xlxy.com
 * 2018-05-23
 * [email protected]
 * All rights Reserved, Designed By WangWei
 * 
*/ public class FileKit { /** * 创建文件 * @param newFile 新文件 * @throws IOException 读写异常 * @return 创建的文件 */ public static synchronized File createFile(File newFile) throws IOException{ if(newFile.exists()){ throw new IOException("文件已存在"); } File dir = newFile.getParentFile(); if (!dir.exists()) { if(!dir.mkdirs()){ throw new IOException("文件夹创建失败"); } } try{ if(!newFile.createNewFile()){ throw new IOException("文件已存在"); } }catch(Exception e){ throw new IOException("创建文件失败"); } return newFile; } /** * 创建文件 * @param newFileName 新文件名 * @throws IOException 读写异常 * @return 创建的文件 */ public static synchronized File createFile(String newFileName) throws IOException{ File newFile = new File(newFileName); return createFile(newFile); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy