public static void main(String[] args) throws Exception {
System.out.println("请输入读取文件(如文本,图片等)的路径:(如:D:\\Img.jpg)");
Scanner scannerIn = new Scanner(System.in);
String fileIn =scannerIn.nextLine();
System.out.println("请输入保存文件的路径。(如:E:\\abc.jpg)");
Scanner scannerout = new Scanner(System.in);
String fileOut =scannerout.nextLine();
FileInputStream fis = new FileInputStream(new File(fileIn));
FileOutputStream fos = new FileOutputStream(new File(fileOut));
byte[] bytes = new byte[1024*1024*4];//最大4M的缓冲区
while (fis.read(bytes)!=-1) {
fos.write(bytes);
}
fis.close();
fos.close();
System.out.println("文件保存成功,请在硬盘上查看"+fileOut);
}
用IO流实现文件复制功能
最新推荐文章于 2022-07-11 22:48:23 发布