tags:

views:

267

answers:

3

Hi,

I've a java package (package A) and I would retrieve a file contained into another package (package B)? How could I do this?

Thanks in advance. Best regards.

+2  A: 

Use the import statement.

For example, to import class Bar from package a.b.c.d into your class in package a.b.c, you would write:

package a.b.c;

import a.b.c.d.Bar;

class Foo {
}
David Grant
A: 

In Java, you cannot get the files of a package, by reflexion or otherwise.

Note that the classes of a package may be in many different folders (with different roots), in jars ..

But if you know your complete classpath, you can (complex task) search yourself in all these different locations...

KLE
+2  A: 

Use this:

ClassA.class.getResourceAsStream("/packageB/yourfile.ext");
Jerome