有哪位能帮我解决一下此题

如何解决Java a.txt内容复制到b.txt

可以使用Files类中的copy方法


public class Test {
    public static void main(String[] args) {
        File a = new File("F:\\a.txt");
        File b = new File("F:\\b.txt");
        try {
            copyFile(a, b);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void copyFile(File a, File b) throws IOException {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream(a);
            output = new FileOutputStream(b);
            byte[] buf = new byte[1024];
            int bytesRead;
            while ((bytesRead = input.read(buf)) > 0) {
                output.write(buf, 0, bytesRead);
            }
        } finally {
            if(input != null){
              input.close();
            }
            if(output != null){
              output.close();
            }
        }
    }
}