NullPointerException
1 import java.io.File; 2 public class TestFile { 3 public static void main(String[] args) 4 { 5 6 File file = new File("C:\\testFile"); 7 8 if(!file.exists()) 9 { 10 11 System.out.println("directory is empty"); 12 // return; //结束对当前这个函数的调用,并跳出这个函数体 13 } 14 15 File[] fileList = file.listFiles(); 16 17 System.out.println(fileList.length); 18 19 20 } 21 22 }
Console 结果:
directory is empty
Exception in thread "main" java.lang.NullPointerException
at LinkedList.TestFile.main(TestFile.java:17)