i have problem when i am accessing package of different directory.

can we access a package in a single java file that are lies in two different drive/directories?

Eg. My one package p1 is in d:/ having class abc.java
My another package p2 is in e:/ having class pqr.java

can i access both this classes in single java file reside at desktop?

how to do so?
please explain.

Thanks

Yes, you can use class files from different directories by adding all the directories to your classpath. If you're using an IDE, you can do so in your project's settings. If you're compiling from the command line, you can use the -classpath switch or the CLASSPATH environment variable to set the class path. On Windows multiple directories are separated by a semicolon.

So if you have p1.abc in d:\stuff\p1\abc.class and p2.pqr in e:\otherstuff\p2\pqr.class, you can compile a class that uses both those classes from the command line like this:

javac -classpath d:\stuff;e:\otherstuff MyClass.java
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.