Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.spec;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- *
- * @author Admin
- */
- public class Test3 {
- public static String getString() throws Exception {
- try ( BufferedReader br = new BufferedReader(new FileReader("some path"))) {
- return br.readLine();
- }
- }
- public static void main(String[] args) {
- // try-with-resource
- try (MyResource resource = new MyResource()) {
- resource.doSomething();
- }catch(Exception ex){
- ex.printStackTrace();
- }
- // try-catch-finnaly
- MyResource resource2 = new MyResource();
- try {
- resource2.doSomething();
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- try{
- resource2.close();
- }catch(IOException ex){
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement