troubleshooting Question

Java Runtime Error

Avatar of Ashok911
Ashok911Flag for United States of America asked on
JavaWeb Servers
8 Comments1 Solution404 ViewsLast Modified:

I Know very little Java. I got a requirement from my client to copy files from one directory to another. I got the following code from Internet. The code got compiled without any error. When I tried to run I am getting the following runtime exception. Please help me to fix this.

C:\Temp>echo %CLASSPATH%
C:\Program Files\VERITAS\Backup Exec\NT\ECM\bumodule.jar;C:\Program Files\VERITAS\Backup Exec\NT\ECM\LOG4J-CORE.JAR;C:\P

C:\Temp>java CopyDirectory('C:\Temp','C:\Y')
Exception in thread "main" java.lang.NoClassDefFoundError: copydirectory('C:\Temp','C:\Y')



public class CopyDirectory{
public static void main(String[] args) throws IOException{
CopyDirectory cd = new CopyDirectory();

String arg1 = args[0];
String arg2 = args[1];
File src = new File(arg1);
File dst = new File(arg2);

cd.copyDirectory(src, dst);

public void copyDirectory(File srcPath, File dstPath)
throws IOException{
if (srcPath.isDirectory()){

if (!dstPath.exists()){


String files[] = srcPath.list();
for(int i = 0; i < files.length; i++){
copyDirectory(new File(srcPath, files),
new File(dstPath, files));



System.out.println("File or directory does not exist.");

InputStream in = new FileInputStream(srcPath);
OutputStream out = new FileOutputStream(dstPath);
// Transfer bytes from in to out
byte[] buf = new byte1024;
int len;
while ((len = > 0) {
out.write(buf, 0, len);


System.out.println("Directory copied.");


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros