import java.io.*;

public class FileCopy {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            System.out.println("请输入被复制图片的路径和文件名:");
            String sourcePath = reader.readLine();
            System.out.println("请输入复制后的位置:");
            String targetPath = reader.readLine();

            FileInputStream fis = new FileInputStream(sourcePath);
            FileOutputStream fos = new FileOutputStream(targetPath);

            byte[] buffer = new byte[1024];
            int len;
            while ((len = fis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fis.close();
            fos.close();
            System.out.println("文件复制成功!");
        } catch (IOException e) {
            System.out.println("文件复制失败:" + e.getMessage());
        }
    }
}

注:以上代码仅供参考,实际应用中需要进行异常处理和错误提示

2、由用户输入被复制图片的路径以及文件名、复制后的位置选用合适的流实现文件复制;请用java代码实现

原文地址: https://www.cveoy.top/t/topic/hocH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录