When I run this code
C:\ankit>java CopyFile.java NewCopyFile.java It will create a new file named "NewCopyFile" and Copy the whole data.
Now when i run this code
C:\ankit>java CopyFile.class NewCopyFile.class It will run successfully but when i type
c:\ankit>java NewCopyFile It gives an error..
Exception in thread "main" java.lang.NoClassDefFoundError: NewCopyFIle (wrong na
Is it not possible to copy the class file? Why?
The error message is pretty clear: you ran "java NewCopyFile", and the JVM tried to load the class "NewCopyFile" out of the file "NewCopyFile.class", but it found that the file actually contains a class named "CopyFile". Since you asked it to run NewCopyFile, and it can't, it reports the error and stops.
In other words, your program copies class files just fine, but class files are required to be named after the class they contain.