Java Reference
In-Depth Information
It is important to understand that the resource declared in the try statement is implicitly
final . This means that you can't assign to the resource after it has been created. Also, the
scope of the resource is limited to the try -with-resources statement.
You can manage more than one resource within a single try statement. To do so, simply
separate each resource specification with a semicolon. The following program shows an
example. It reworks the CopyFile program shown earlier so that it uses a single try -with-
resources statement to manage both fin and fout .
In this program, notice how the input and output files are opened within the try :
Search WWH ::




Custom Search