P
Philipp
Dear all,
Is this (see code) the correct way of handling a FileOutputStream?
Specific question are in the code. Thanks for your answers. Philipp
public void load(File file){
OutputStream os;
try {
os = new FileOutputStream(file);
} catch (Exception e) {
logger.log("Could not open file output stream", e);
// can os be non-null here?
// should I put a close() here?
return;
}
try {
load(os); // call of another load method with OutputStream
} catch (Exception e) {
logger.log("Exception while loading from file.", e);
return; // is this return of any interest?
} finally {
if(os != null){
try {
os.close();
} catch (Exception e) {
// exception while closing, what can we do?
}
}
}
}
Is this (see code) the correct way of handling a FileOutputStream?
Specific question are in the code. Thanks for your answers. Philipp
public void load(File file){
OutputStream os;
try {
os = new FileOutputStream(file);
} catch (Exception e) {
logger.log("Could not open file output stream", e);
// can os be non-null here?
// should I put a close() here?
return;
}
try {
load(os); // call of another load method with OutputStream
} catch (Exception e) {
logger.log("Exception while loading from file.", e);
return; // is this return of any interest?
} finally {
if(os != null){
try {
os.close();
} catch (Exception e) {
// exception while closing, what can we do?
}
}
}
}