views:

49

answers:

2

So I'm attempting to read a file in an Eclipse Java project. The resource itself is in a linked folder that I've added using:

New -> Folder. Advanced >> Link folder etc.

I couldn't open the file so I wrote a simple method to find out what I could access:

public static void main(String[] args)
{
    File folder = new File(".");
    String[] listOfFiles = folder.list();

    for (int i = 0; i < listOfFiles.length; i++)
    {
        System.out.println("file: " + listOfFiles[i]);
    }
}

This leaves me with the following output:

file: .classpath
file: .project
file: bin

So how do I open files in Eclipse from a linked folder location?

If I can't, what's the purpose of Linked Folders?

Thanks in advance.

+1  A: 

The only thing i can see that works is if you edit your debug configuration's classpath user entries to click the Advanced... button and click add folders, and select that folder, then if you want to get that file you can do

InputStream is = Someclass.class.getResourceAsStream("filename_in_your_linked_folder")

so i suppose i don't think it's really of much use for what you want.

MeBigFatGuy
+1  A: 

At runtime, your main method is not aware of any Eclipse configuration. Running it from Eclipse gives the same result than running it from command line. So, since the linked resources are not physically present in the directory of your project, the ouput you get is the expected one.

Linked resources can be useful for anything controlled by Eclipse (mainly source or output directories).

Damien