Solved

how do i import files?

Posted on 2004-08-10
11
193 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:iamnamja
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:bcladd
ID: 11768702
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.
0
 

Author Comment

by:iamnamja
ID: 11768747
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.
0
 
LVL 11

Accepted Solution

by:
bcladd earned 25 total points
ID: 11768872
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...

    -or-

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

    where:

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

    classpath1;classpath2
        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.

0
 
LVL 35

Expert Comment

by:girionis
ID: 11770074
Where are the class files you are trying to import and what is your CLASSPATH variable?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:mayankeagle
ID: 11770451
0
 

Author Comment

by:iamnamja
ID: 11775156
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.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 11780650
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?
0
 
LVL 3

Expert Comment

by:JohnnyAffa
ID: 11781709
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 :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now