java2核心技术第一卷第12章中一个打印目录文件名的程序,应该会有用处:import java.io.*;public class FindDirectories
{ public static void main(String[] args)
{ if (args.length == 0) args = new String[] { ".." }; try
{ File pathName = new File(args[0]);
String[] fileNames = pathName.list(); for (int i = 0; i<fileNames.length; i++)
{ File tf = new File(pathName.getPath(),
fileNames[i]);
if (tf.isDirectory())
{ System.out.println(tf.getCanonicalPath());
main(new String [] { tf.getPath() });
}
}
}
catch(IOException e)
{ System.out.println("Error: " + e);
}
}
}
//代码中没有用到的方法getCanonicalFile()是显示全部规范化的文件名,具体用法请见api
{ public static void main(String[] args)
{ if (args.length == 0) args = new String[] { ".." }; try
{ File pathName = new File(args[0]);
String[] fileNames = pathName.list(); for (int i = 0; i<fileNames.length; i++)
{ File tf = new File(pathName.getPath(),
fileNames[i]);
if (tf.isDirectory())
{ System.out.println(tf.getCanonicalPath());
main(new String [] { tf.getPath() });
}
}
}
catch(IOException e)
{ System.out.println("Error: " + e);
}
}
}
//代码中没有用到的方法getCanonicalFile()是显示全部规范化的文件名,具体用法请见api
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货