Switch to full style
Java Technology Tutorials Written By Members.
Post a reply

try-with-resource automatic handling

Mon Nov 05, 2012 4:36 pm

At Java7, the try statement handles the resources and free them once they are no longer needed in the class automatically without the need to add a finally step to free them by your self.
java code
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
 
public class ReadMyFile {

    public static void main(String args[]) {
        BufferedReader myBufferReader = null;

        String filePath = "C://java.txt";
        try {
            myBufferReader = new BufferedReader(new FileReader(filePath));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 




Post a reply
  Related Posts  to : try-with-resource automatic handling
 Need automatic adding to catalogs     -  
 Automatic Pairing and initialization of com port     -  
 Automatic change to webpage background image     -  
 What is Event Handling?     -  
 Exception handling     -  
 Exception Handling in a project     -  
 Material Handling Equipment     -  
 Error handling in AJAX     -  
 Event Handling Notes     -  
 Session handling using Struts     -  

Topic Tags

Java Exceptions