Java try-catch-finally Exception Handling



Αξιολόγηση Χρήστη:  / 0
ΧειρότεροΚαλύτερο 
Λεπτομέρειες

try-catch-finally simple code in java :

View source
package com.developerpages.snippets.basics;
 
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
 
public class trycatsfinalyexample {
 
    public static void main(String[] args) throws FileNotFoundException {
        FileReader in = null;
        try {
            in = new FileReader("test.txt");
            // processing file ...
        } catch (IOException ex) {
            System.out.println("Error opening file...");
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ex) {
                    System.out.println("Cannot close file ...");
                }
            }
        }
    }
}


You have no rights to post comments

   
   

     

© Developerpages