My situation is simple.
I have this in my program:
File folder = new File("input");
File[] listOfFiles = folder.listFiles();
System.out.println(listOfFiles.length);
I just want to put all the path of files from the folder “input” to an array.
It works fine by running with eclipse.When I try to do this in cmd, it gives me an null pointer exception. My java file is in this directory:
C:\Users\JHeng\Desktop\java stuff\converter\src
Thanks for responding!
If I put the absolute directory in the first line:
File folder = new File("C:\\Users\\JHeng\\Desktop\\java stuff\\converter\\src\\input");
When I run it in eclipse, eclipse even gives me a null pointer exception in the line
System.out.println(listOfFiles.length);
Thanks in advance!
It obviously a problem of workspace. Now try the below code…….
But first be sure you have “src” folder on the specified path…, which is passed in File constructor as an argument below.