try-catch块的try后面可以接参数么?刚刚看到一段代码,没碰到过这种形式,期待大神解答!
- public void initPool(String fileName) throws InstantiationException,
- IllegalAccessException, ClassNotFoundException {
- try (FileInputStream fis = new FileInputStream(fileName)) {
- Properties props = new Properties();
- props.load(fis);
- for (String name : props.stringPropertyNames()) {
- // 每取出一对Key-Value对,就根据valude创建一个对象
- // 调用createObject()创建对象,并将对象添加到对象池中
- objectPool.put(name, creatObject(props.getProperty(name)));
- }
- } catch (IOException e) {
- // TODO: handle exception
- System.out.println("读取" + fileName + "异常");
- }
- }
复制代码
|