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.
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.
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 {
}
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...
Use this:
ClassA.class.getResourceAsStream("/packageB/yourfile.ext");