如何使用java代码创建多级目录及文件呢?
									下文笔者讲述使用java代码创建多级目录及目录下文件的方法分享,如下所示
				 
				
实现思路:
    1.使用mkdirs方法即可创建多级目录
    2.借助createNewFile()方法即可创建指定文件
 例:
//www.java265.com创建多级目录示例代码
//获取文件路径
String dir = filePath.substring(0,filePath.lastIndexOf("\\"));
File file =  new File(dir);
if(!file.exists()){
    //创建目录
	file.mkdirs();
}
//定义文件路径
String testFile = dir+"\\"+(filePath.substring(filePath.lastIndexOf("\\"),filePath.length()));
File file1 =  new File(testFile);
if(!file1.exists()){
	try {
	    //创建文件
		file1.createNewFile();
	} catch (IOException e) {
		throw new PlatException("创建文件失败:"+e.getMessage());
	}
}
									
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

			
               
               
               
               
          
