Re: [問題] 請問如何以相對路徑的方式列出目錄
※ 引述《Nt1 (用功點吧!)》之銘言:
: 假設我的目錄結構是這樣:
: c:\test\test1
: c:\test\test2
: c:\test\test3
: 我想把 test 底下的目錄列出來,於是寫了下列的程式:
: File file = new File("c:\\test");
: File[] files = file.listFiles();
: for (int i=0;i<files.length;i++)
: {
: if (files[i].isDirectory())
: System.out.println(files[i].getPath());
: }
: 但他列出來的結果是絕對路徑,也就是 c:\test\test1.....
: 請問有沒有辨法可以讓他列出來是像 \test1 \test2 \test3 只有目錄名稱的方法呢?
: 目前想到可以用 replace 的方式@@ 但好像不怎麼聰明
getPath()
Converts this abstract pathname into a pathname string.
getName()
Returns the name of the file or directory denoted by this abstract pathname.
你要用的是getName()喔
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.132.7.82
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):