java在linux下发布的ftp上创建文件夹
代码在windows的ftp上创建文件夹没问题,但是在linux的ftp上死活创建不了,是因为反斜线的问题,windows上用/就可以,在linux上需要用\,代码如下
remotePath="123"+"\\" + "20200104" + "\\" + "222";
boolean ftppath = ftpClient.changeWorkingDirectory(remotePath);
if(!ftppath) {
//如果目录不存在创建目录
String[] dirs = remotePath.split("\\\\");
String tempPath = "";
for (String dir : dirs) {
if (null == dir || "".equals(dir)) {
continue;
}
// tempPath += "\\\\" + dir;
tempPath = dir;
if (!ftpClient.changeWorkingDirectory(tempPath)) {
if (!ftpClient.makeDirectory(tempPath)) {
System.out.println("创建文件夹失败,路径" + tempPath);
// ftpClient.disconnect();
// return success;
} else {
ftpClient.changeWorkingDirectory(tempPath);
}
}
}
}