Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.io问题解决

今天在写一个简单的java测试程序的时候,报了如下的错误


Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.io
	at java.lang.ClassLoader.preDefineClass(ClassLoader.java:649)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:785)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)



给出我写的代码:

package java.io;

public class JudgePathIsOrNotDirectory {

	public static void main(String[] args) {
		File f = new File("d:"+File.separator);
		if(f.isDirectory()){
			System.out.println(f.getPath()+"是目录");
		}else{
			System.out.println(f.getPath()+"不是目录");
		}
	}
}



看完错误才明白是自己的包名和java自带的报名冲突了,不能和jdk的宝一样啊,package java.io;有问题。改完之后就好了

你可能感兴趣的:(Java基础学习与总结)