例如:读入 /home/java/photo.jpg 则创建一个文件 /home/java/copy_photo.jpg 新文件内容和原文件内容 相同
package io.homework; import java.io.*; import java.util.Scanner; public class q23 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); File file = new File(s); boolean flag = file.isFile(); System.out.println(flag); if (flag) { try(InputStream is = new FileInputStream(s); BufferedInputStream bis = new BufferedInputStream(is); OutputStream os = new FileOutputStream("copy_"+s); BufferedOutputStream bos = new BufferedOutputStream(os)) { byte[] bs = new byte[1024]; while (true) { int len = bis.read(bs); if (len == -1) break; bos.write(bs); } } catch (Exception e) { e.printStackTrace(); } } } }