Reputation: 311
code:
File folder = new File("src/zipper");
File[] listOfFiles = folder.listFiles();
File s=listOfFiles[0];
Work excellent from eclipse but from the cmd(windows) I get this error:
Exception in thread "main" java.lang.NullPointerException
at testFile.main(testFile.java:23)
Line 23 is:
File s=listOfFiles[0];
Zipper is a folder with a lot of folders inside it and each of them has a zip file.
Upvotes: 1
Views: 49
Reputation: 296
try passing the full path like c:\myfolder\src and then see what you get. May be where you are running the src folder is not the correct relative path.
Upvotes: 0
Reputation: 1937
From https://docs.oracle.com/javase/7/docs/api/java/io/File.html#listFiles():
Returns: An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
It would seem that you are getting null because the working directory from where you are launching Java does not hold the src/zipper folders.
Upvotes: 2