package wcl;
import java.io.File; import java.io.IOException;
public class TestFile { public static void main(String[] args){ File dir = new File("."+File.separator+"demo"); if(!dir.exists()){ dir.mkdirs(); } File file = new File(dir,"demo.text"); if(!file.exists()){ try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(file.getAbsolutePath()); System.out.println(file.getName()); } } 此程序在C盘下 wcl文件夹内 这个程序在Myeclipse里运行正常 但是在cmd下编译通过运行不了出异常: C:\>cd wcl
C:\wcl>javac TestFile.java
C:\wcl>java TestFile Exception in thread "main" java.lang.NoClassDefFoundError: TestFile (wrong name: wcl/TestFile) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) 检查过环境变量配置。在cmd上输入java -version , java ,javac 命令 都是正常的 实在是找不到解决问题的方法 求救!
|