【发布时间】:2019-11-06 13:10:54
【问题描述】:
在我的 Windows 应用程序中,我想通过 FTP 使用 SimpleFileVisitor<Path> 删除服务器上的目录结构。它因“找不到文件”而失败,因为在下面的代码中,分隔符被更改为反斜杠。显然,服务器希望它是正斜杠。我怎样才能让它保持为正斜杠?
public class FTPTest {
static String server ;
static int port ;
static String user ;
static String pass;
static FTPClient theFtpClient;
public FTPTest(){
server = "nx.dnslinks.net";
port = 21;
user = "xxxx";
pass = "#xxxxx";
theFtpClient = new FTPClient();
}
static void deleteDirectoryWalkTree(Path path) throws IOException {
FileVisitor visitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null) {
throw exc;
}
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
};
Files.walkFileTree(path, visitor);
}
public static void main(String[] args) {
FTPTest theFTPTest = new FTPTest();
Path Path = Paths.get("/httpdocs/manual-uploads/TestingFTPUtil/SubDir_1/SubDir_2");
try {
theFTPTest.deleteDirectoryWalkTree(Path);
} catch (IOException ex) {
Logger.getLogger(FTPTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
【问题讨论】:
-
我没有看到,您的编辑对您的问题有什么改变,也没有看到我的答案的相关性。