java遍历文件夹
public static void traverseFolder2(String path) {
? ? ? ? File file = new File(path);
? ? ? ? if (file.exists()) {
? ? ? ? ? ? File[] files = file.listFiles();
? ? ? ? ? ? if (null == files || files.length == 0) {
? ? ? ? ? ? ? ? System.out.println("文件夾是空的!");
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? for (File file2 : files) {
? ? ? ? ? ? ? ? ? ? if (file2.isDirectory()) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("文件夾:" + file2.getAbsolutePath());
? ? ? ? ? ? ? ? ? ? ? ? traverseFolder2(file2.getAbsolutePath());
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("文件:" + file2.getAbsolutePath());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? } else {
? ? ? ? ? ? System.out.println("文件不存在!");
? ? ? ? }
? ? }
總結(jié)
- 上一篇: mybatis使用if判断参数是否为空
- 下一篇: @RequestParam和@Reque