


How to determine whether a multi-level path exists in java and create it if it does not exist
方案一:
(带文件名的Path:如:D:\news\2014\12\abc.text)
例如:
public boolean isexitsPath(String path)throws InterruptedException{ String [] paths=path.split("\\\\"); StringBuffer fullPath=new StringBuffer(); for (int i = 0; i < paths.length; i++) { fullPath.append(paths[i]).append("\\\\"); File file=new File(fullPath.toString()); if(paths.length-1!=i){//判断path到文件名时,无须继续创建文件夹! if(!file.exists()){ file.mkdir(); System.out.println("创建目录为:"+fullPath.toString()); Thread.sleep(1500); } } } File file=new File(fullPath.toString());//目录全路径 if (!file.exists()) { return true; }else{ return false; } }
注意:带文件名的path,需要判断是否path中已经包含文件名,若包含,则不再创建文件夹。
在线视频教程分享:java在线教程
(不带文件名的Path:如:D:\news\2014\12)
例如:
方案二:
(带文件名的Path:如:D:\news\2014\12\abc.text)
(不带文件名的Path:如:D:\news\2014\12)
注意:带文件名和不带文件名的处理方式的区别就在于循环的长度上。
推荐相关文章教程:java入门程序
The above is the detailed content of How to determine whether a multi-level path exists in java and create it if it does not exist. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)