亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么分隔符會被 Path parentPath = Paths.get(strPath) 改變?

為什么分隔符會被 Path parentPath = Paths.get(strPath) 改變?

陪伴而非守候 2023-02-16 16:37:47
在我的 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);    }}}
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

PathPathsclasses 用于將您的代碼與本地操作系統的路徑語法隔離開來。

雖然您想使用遠程FTP 系統的路徑,但它可能(確實)使用不同的語法。主要是相同的語法,無論您的代碼恰好在哪個本地操作系統上運行。

所以你不應該使用PathPathsclasses 作為 FTP 路徑。


查看完整回答
反對 回復 2023-02-16
  • 1 回答
  • 0 關注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號