Re: [問題] 請問書上案例編譯錯誤找不到問題!?
據 A 君說,他印出來的結果都是被判斷為檔案不是目錄
import java.io.File;
public class right {
public static void main(String[] args) {
String path = "C:\\Program Files\\Java\\jdk1.6.0";
File rootPath = new File(path);
String[] stringArray = rootPath.list();
File[] fileArray = rootPath.listFiles();
assert stringArray.length == fileArray.length;
for(int i=0; i<stringArray.length; i++) {
boolean isSame = fileArray[i].isDirectory() == new
File(stringArray[i]).isDirectory();
System.out.println(isSame +" : "+fileArray[i].getName());
}
}
}
=======================================================================
false : bin
true : COPYRIGHT
false : db
false : demo
false : include
false : jre
false : lib
true : LICENSE
true : LICENSE.rtf
true : README.html
true : README_ja.html
true : README_zh_CN.html
false : sample
true : src.zip
true : THIRDPARTYLICENSEREADME.txt
=========================================================================
有些目錄會有判定不一致的情況
看來用 listFiles 比較準,但是很傷資源
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.231.49.37
※ 編輯: qrtt1 來自: 61.231.49.37 (09/15 01:18)
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 2 之 5 篇):