2012-08-27 51 views
2

在Java 7中使用試用資源時,是否有任何有關.close()被調用順序的保證?try-with-resources:Java是否對調用.close()的順序做出任何保證?

下面是從Oracle一些示例代碼顯示這樣的特徵:

try (
    java.util.zip.ZipFile zf = new java.util.zip.ZipFile(zipFileName); 
    java.io.BufferedWriter writer = java.nio.file.Files.newBufferedWriter(outputFilePath, charset) 
) { 

    // Enumerate each entry 

    for (java.util.Enumeration entries = zf.entries(); entries.hasMoreElements();) { 

    // Get the entry name and write it to the output file 

    String newLine = System.getProperty("line.separator"); 
    String zipEntryName = ((java.util.zip.ZipEntry)entries.nextElement()).getName() + newLine; 
    writer.write(zipEntryName, 0, zipEntryName.length()); 
    } 

兩個zf.close()writer.close()將被調用。訂單是否有保證?

回答

相關問題