¿¹Á¦
public class
ClassA {
public void
makeStream (File file) {
try
{
FileOutputStream stream =
new
FileOutputStream(file);
stream.write(7);
//do something...
stream.close();
}
catch
(IOException e) {
//stream leaked...
}
}
}
¼Ö·ç¼Ç
ÀÚ¿ø ´©¼ö¸¦ ÇÇÇÏ·Á¸é ¸ðµç java.io.FileOutputStream¿¡¼ close()°¡ È£ÃâµÇ´ÂÁö È®ÀÎÇϽʽÿÀ.
Âü°í: ÀÌ ±ÔÄ¢Àº ¸ðµç FileOutputStream »ý¼ºÀÚ Çü½Ä¿¡ Àû¿ëµË´Ï´Ù.
public class
ClassA {
public void
makeStream (File file) {
FileOutputStream stream =
null
;
try
{
stream =
new
FileOutputStream(file);
stream.write(7);
//do something...
}
catch
(IOException e) {
//do something...
}
finally
{
if
(stream !=
null
) {
try
{
stream.close();
}
catch
(IOException e) {
//do something...
}
}
}
}
}