IO创建抽象类&&【异常处理1】Error occurred during initialization of boot layer

步骤
1.创建源
2.选择流
3.操作
(1)读
(2)写
4.释放资源

File e=new File("abc.txt");
		InputStream i=null;
		try {
			 i=new FileInputStream(e);
			int emp;
			try {
				while((emp=i.read())!=-1) {
					System.out.print((char)emp);
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}finally {
			if(i!=null) {
				try {
					i.close();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		}

【异常处理1】Error occurred during initialization of boot layer

Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: D:\mycode\IO\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: IOtest01.class found in top-level directory (unnamed package not allowed in module)

1.网上第一个解决方法,对我来说没有用
初始化引导层期间发生错误。
在顶级目录中找到helloMyJava.class(模块中不允许使用未命名的包)。
原因是JDK9及以上版本中,引入了模块。所以要是在default package建立一个单独运行的类,就无法通过编译。在JDK8中就没有这样的问题。
同时,如果依然想在default package中运行单独的类。删除module-info.java就可以了。

2.网上第二个解决方法,有效
创建项目的时候,改为JavaSE-1.8
IO创建抽象类&&【异常处理1】Error occurred during initialization of boot layer_第1张图片

你可能感兴趣的:(IO创建抽象类&&【异常处理1】Error occurred during initialization of boot layer)