开发者

Read a file in java from a linked folder in eclipse

开发者 https://www.devze.com 2023-01-22 11:33 出处:网络
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:

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 stat开发者_运维技巧ic 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.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消