作者bennylu (Benny)
看板java
标题Re: [问题] 请问如何以相对路径的方式列出目录
时间Thu Aug 24 20:24:25 2006
※ 引述《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