Link to home
Start Free TrialLog in
Avatar of iamnamja
iamnamja

asked on

how do i import files?

Hi, I'm just starting to learn java.  But I want to be able to import files that are not in the original java library.  I have made a separate folder in which there are some files that I would like to import but I keep getting an error saying that it does not exist.  I'm using comand promt, and I guess I have to set it somehow, but I don't know how.  Please help
Avatar of bcladd
bcladd

on both the java compiler (javac) and the java interpreter, you need to set the classpath.

javac -classpath directorypath MyClass.java

java -classpath directorypath MyClass

then your import statements should work.
Avatar of iamnamja

ASKER

Could i just add classpath to the eviornment variables?  So, for example... classpath c:\classes.  Would that work?  Because I have a couple in a different folders and I want to access all of them.  And I tried to do javac -classpath c:\classes, but that doesn't seem to work for some reason and i get errors.
ASKER CERTIFIED SOLUTION
Avatar of bcladd
bcladd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of girionis
Where are the class files you are trying to import and what is your CLASSPATH variable?
Well, in c:, i have a folder called j and in there i have many folders some which have more folders, or which have different files that i would like to import.
Example: if your folder C:\FOLDER1 contains a file called File1.class which you would like to use in your program, use:

set CLASSPATH=%CLASSPATH%;C:\FOLDER1

Do you have those files in a package? Or are they in the default package? Did you read the link I posted?
iamnamja,

to save you time from setting classpath everytime you run an app, edit autoexec.bat
to include

set classpath=%CLASSPATH%;C:\classes

that will set your existing class path as well as c:\classes you can add additional classes delimtered by the semi colon ;

by editing autoexec.bat you set you clasapath at bootup. alot less hassle :)