当前位置:网站首页>ftp不能创建多级目录【循环创建问题】
ftp不能创建多级目录【循环创建问题】
2022-07-21 05:02:00 【彩虹海。】
关于报表导出用上了ftp文件服务器,最开始用字符串存储了文件上传路径,然后使用ftp.makedir(path),后来发现好像不能用它自带的方法创建多级目录。然后上网查,根据大佬们的博客得到了适用的多级目录创建方法。在此可以记录一下。
/**
* ftp创建目录——ftpClient只支持一级一级创建
*
* @param ftp
* @param path
* @return
* @throws IOException
*/
boolean makeDir(FTPClient ftp, String path) throws IOException {
// 分割
String[] paths = path.split("/");
// 创建成功标识
boolean isMakeSucess = false;
// 遍历每一级路径
for (String str : paths) {
// 切换目录,根据切换是否成功判断子目录是否存在
boolean changeSuccess = ftp.changeWorkingDirectory(str);
// 该级路径不存在就创建并切换
if (!changeSuccess) {
isMakeSucess = ftp.makeDirectory(str);
ftp.changeWorkingDirectory(str);
}
}
return isMakeSucess;
}
边栏推荐
猜你喜欢
AS编辑器设置Flutter开发右侧代码缩进位置
利用反汇编调试与补码解释0x80000000 / -1整形输出异常不一致
数据类型Map判空 、空字符串、空key值等各种判断方法,全网最详细
Trigonometric formula of 3D mathematics
Data type map, empty string, empty key value and other judgment methods are the most detailed in the whole network
Paper reading (61):multi instance attention network for few shot learning
JSON tool class
Let you say goodbye to the project maintenance mode of 996
微信公眾號開發接入,利用微信公眾平臺申請測試號進行本地開發
Pycharm创建SQLite数据库
随机推荐
MySQL之DQL(数据查询语言)- 表连接查询
Quartz create scheduled tasks (getting started)
原子引用解决ABA问题
Project of integrating SSM framework
整合ssm框架的项目
Array and object copy of ES6
MySQL exception: Legal mix of settlements (utf8_general_ci, implicit) and (utf8mb4_general_ci, coalible)***
论文阅读 (61):Multi-Instance Attention Network for Few-Shot Learning
汇编借助于条件转移实现循环判断是否为平方数
MySQL DQL (data query language) - common functions
微信公眾號開發接入,利用微信公眾平臺申請測試號進行本地開發
One of the problems to solve the sorting order error of Oracle database query single table
Error in pulling project POM file, Jai_ core-1.1.3. Jar, solve the problem of introducing jar
In fastjason data type, there is a problem of $ref: "$.list[0]" when parsing jsonobject
Docker installation mysql8 in CentOS 8
Wechat official account development access, using wechat public platform to apply for test number for local development
14. 你能说说进程与线程的区别吗
14. Can you tell the difference between process and thread
Gaode map API obtains the surrounding information corresponding to the current location
Data type map, empty string, empty key value and other judgment methods are the most detailed in the whole network