按照书中的代码写的,
private FileInputStream in = null;//声明Fileinputstream对象in
public void readInfo() {
try {
//创建FileInputStream对象in
in = new FileInputStream("src/com/mingrisoft/closeio.java");
System.out.println("创建io流,分配内存资源");
}catch(IOException io) {
io.printStackTrace();
System.out.println("创建io对象发生异常。");
}finally {
if(in != null) {
try {
in.close();//关闭fileinputStream对象in,释放资源
System.out.println("关闭io流,释放内存资源");
}catch(IOException ioe) {
ioe.printStackTrace();//输出栈踪迹
System.out.println("关闭io对象发生异常");
}
}
}
}
public static void main(String[] args) {
CloseIo ex = new CloseIo();//这里出现问题!!!!!!!!!!!!!!!!!!!!
ex.readInfo();
}
用的是eclipse,因为书上是用这个软件,不换成idea是因为换了软件教材就不适用了,在学习的过程中总是遇到这种问题,我看网上又说按shift+control+o可以自动引入,但是这个我按了也是这样提示,请问各位这个要怎么解决呢??
CloseIo 应该是用户自定义的类,JDK 中没这个类,你看看书上有没有相关定义吧。
既然是书上的代码,那应该有在开头就写了的,就是 import 开头的语句。
这个CloseIo是别人的类名吧,new 一个类对象.然后调用类的方法.你自己的类名是啥就是啥类.