user1539343
user1539343

Reputation: 1669

Running the program to show current directory contents in eclipse gives a result which seems confusing

I have this program:

System.out.println("files: ");
        dir = new File(".");
        File[] files = dir.listFiles(f -> {return f.getName().toLowerCase().endsWith(".java");});

        System.out.println(dir.getAbsolutePath());

        for (String f: dir.list()) {
            System.out.println(f);
        }

I am running the program from eclipse which gives me the following result:

files: 
C:\Users\rezbi\workspace\Misc\.
.classpath
.project
.settings
bin
src

This is confusing because the current directory is supposed to be the classes or bin directory with all the class files. Please enlighten.

Upvotes: 0

Views: 1672

Answers (2)

ralph.mayr
ralph.mayr

Reputation: 1340

When running a Java program in Eclipse, you can define which directory to use as the Working directory in the launch configuration. By default this is the location of the project, not the bin subfolder. (Even though you can easily change it to that if you like.)

enter image description here

Upvotes: 4

Vasily Liaskovsky
Vasily Liaskovsky

Reputation: 2528

This is specific to how Eclipse runs your applications from within IDE. Your projects's root is default option for program's working directory.

You can manually set program's working directory (and many other options!) from "Run Configurations.." menu item.

Upvotes: 2

Related Questions