I have a program where I'm declaring some streams as part of a try block and then attempting to close them as part of the finally block..... I have a book that does something very similar to this (but I'm thinking it must be a little different because it doesn't actually work for me)... within the finally block, my streams are 'unable to be resolved' - which makes some sense. What is the conventional way of doing this?
public static void main(String[] args) {
try {
String source = args[0];
String target = args[1];
String line = null;
String token = null;
StringTokenizer st = null;
FileInputStream istream = new FileInputStream(source);
FileOutputStream ostream = new FileOutputStream(target);
DataInputStream dis = new DataInputStream(istream);
DataOutputStream dos = new DataOutputStream(ostream);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(dos));
<Some Code>
} catch (FileNotFoundException ex) {
<Handle Exception>
} catch (IOException ex) {
<Handle Exception>
} finally {
bw.flush();
bw.close();
br.close();
dis.close();
dos.close();
istream.close();
ostream.close();
}
}