There is nothing wrong with your code. It should list all of the files and directories directly contained by the nominated directory.
The problem is most likely one of the following:
The "."
directory is not what you expect it to be. The "."
pathname actually means the "current directory" or "working directory" for the JVM. You can verify what directory "."
actually is by printing out dir.getCanonicalPath()
.
You are misunderstanding what dir.listFiles()
returns. It doesn't return all objects in the tree beneath dir
. It only returns objects (files, directories, symlinks, etc) that are directly in dir
.
The ".classpath"
file suggests that you are looking at an Eclipse project directory, and Eclipse projects are normally configured with the Java files in a subdirectory such as "./src"
. I wouldn't expect to see any Java source code in the "."
directory.
Can anyone explain to me why src isn't the current folder?"
Assuming that you are launching an application in Eclipse, then the current folder defaults to the project directory. You can change the default current directory via one of the panels in the Launcher configuration wizard.