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
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

bcladdConnect With a Mentor Commented:
List of multiple directories are separated by semicolons.      

From Java's documentation:

The class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.

    C:> sdkTool -classpath classpath1;classpath2...


    C:> set CLASSPATH=classpath1;classpath2...


        A command-line tool, such as java, javac, or javadoc. For a listing, see SDK Tools.

        Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:

            * For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
            * For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
            * For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

        Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

        The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

        Classpath entries that are neither a directory nor an archive (.zip or .jar file) are ignored.

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

javac -classpath directorypath

java -classpath directorypath MyClass

then your import statements should work.
iamnamjaAuthor Commented:
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.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Where are the class files you are trying to import and what is your CLASSPATH variable?
Mayank SAssociate Director - Product EngineeringCommented:
iamnamjaAuthor Commented:
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.
Mayank SAssociate Director - Product EngineeringCommented:
Example: if your folder C:\FOLDER1 contains a file called File1.class which you would like to use in your program, use:


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

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 :)
All Courses

From novice to tech pro — start learning today.