在扫描过程中发现一个问题,会出现类似(E:\\System Volume Information)这种路径。这种路径会报空指针,我在系统设置里面设置了显示隐藏文件,也看不到这个东西。有知道具体原因的大佬,请为小弟指点迷津。
package org.aijiao.test;
import java.io.File;
public class TestRecursion {
1public static void main(String\[\] args) { 2 scanFile("E:\\\\"); 3} 4 5private static void scanFile(String filePath) { 6 File file = new File(filePath); 7 if (file.isDirectory()) { 8 String\[\] fileList = file.list(); 9 //防止扫描到的路径中出现类似(E:\\\\System Volume Information)的路径,这种路径会报空指针异常 10 if (fileList != null) 11 for (int i = 0; i < fileList.length; i++) { 12 String path = file.getAbsolutePath() + "\\\\" + fileList\[i\]; 13 scanFile(path); 14 } 15 } else { 16 System.out.println("文件路径:" + file.getAbsoluteFile()); 17 } 18}
}