java 不允许默认构造_Java错误:默认的构造函数不能处理异常类型FileNotFound异常...

无论是在你的子类抛出FileNotFoundException声明一个显式构造:

public MySubClass() throws FileNotFoundException {

}

或环绕有try-catch块在基类中的代码,而不是抛出一个FileNotFoundException异常:

public MyBaseClass() {

FileInputStream fstream = null;

try {

File inFile = new File("textfile.txt");

fstream = new FileInputStream(inFile);

// Get the object of DataInputStream

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

// Do something with the stream

} catch (FileNotFoundException ex) {

Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);

} finally {

try {

// If you don't need the stream open after the constructor

// else, remove that block but don't forget to close the

// stream after you are done with it

fstream.close();

} catch (IOException ex) {

Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);

}

}

}

无关,但是由于您正在编写Java小程序,请记住您需要sign it才能执行IO操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值