使用finally关闭流

我是Java的新手,刚刚了解到我应该在try / catch / finally块中关闭流,但这迫使我在finally包装中使用另一个try-catch,否则我必须抛出Exception。

这段代码来自练习,我不仅在尝试通过它,而且还在建立良好的编码习惯。您能接受我的结账方法吗?随时批评代码的其他方面,并将其拆散。那是我会变得更好的唯一方法。

/* 
Read 2 file names from the console: file1, file2.
Write all the bytes in file1 to file2, but in the reverse order.
Close the streams.

Requirements:
1. The program should read a file name twice from the console.
2. Use FileInputStream to read from a file, and use FileOutputStream to write to a file.
3. In the second file, you need to write all the bytes from the first file in the reverse order.
4. The FileInputStream and FileOutputStream must be closed.

*/

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Solution {

    private void copyArray () {
        FileInputStream input = null;
        FileOutputStream output = null;

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter a filename to be read: ");
            String file1 = reader.readLine();
            System.out.print("Enter a filename to write to: ");
            String file2 = reader.readLine();

            input = new FileInputStream(file1);
            output = new FileOutputStream(file2);

            byte[] buffer = new byte[input.available()];

            int count = input.available();
            input.read(buffer);
            for (int i = count-1; i>=0; i--) {
                output.write(buffer[i]);
            }
        } catch (IOException e) {
            System.out.println("General I/O exception: " + e.getMessage());
        } finally {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws IOException {
          new Solution().copyArray();
    }
}