public static void main(String[] args) throws IOException
{
File file = new File("C:\\");
String[] filenames;
String fullpath = file.getAbsolutePath(); // 取得路徑
if (file.isDirectory())
{
filenames = file.list();
for (int i = 0; i < filenames.length; i++)
{
File tempFile = new File(fullpath + "\\" + filenames[i]);
if (tempFile.isDirectory())
{
System.out.println("目錄:" + filenames[i]);
}
else
System.out.println("檔案:" + filenames[i]);
}
}
else
System.out.println("[" + file + "]不是目錄");
}
by ting
請先 登入 以發表留言。