Ez metódus, nem függvény.
Ha Java-ra akarjuk fordítani a pszeudo kódomat, akkor pl. ilyesmi:
try(FileInputStream resource = new FileInputStream("file.txt")) { // openResource
// useResource
} // close
vagy
InputStream input = null;
try {
    input = new FileInputStream("file.txt");
    // useResouce
} finally {
    if(input != null) {
        input.close(); 
    }
}