博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java io 复制图片 音频,视频 都好用啊
阅读量:6992 次
发布时间:2019-06-27

本文共 1493 字,大约阅读时间需要 4 分钟。

hot3.png

/* *  *能 复制图片,声音文件,视频文件 */package exe.io;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;public class Copy1 { public void  copy(File srcFile, File targetFile)  { /** * srcFile为源文件,targetFile目标文件 *  * */ if(srcFile == null || targetFile == null) { System.out.println("文件打开失败"); return; } // 2.建立管道 OutputStream os = null; FileInputStream is = null; try { os = new FileOutputStream(targetFile); is = new FileInputStream(srcFile); // 3.读取操作 // 先建立缓冲区,为1024个字节大小 byte [] b = new byte[1024]; int len = 0; // 采用循环的方式读取文件的内容 while ((len= is.read(b)) != -1) { String data = new String (b, 0, b.length); // System.out.println(data); os.write(b); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ // 一般先开的后关 try { if(os != null) os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(is != null)  is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public static void main(String [] args) throws IOException { File srcFile = new File("C:\\Users\\Administrator\\Desktop\\1.jpg "); File targetFile = new File("C:\\Users\\Administrator\\2.jpg"); new Copy1().copy(srcFile, targetFile); }}

转载于:https://my.oschina.net/u/1465640/blog/207909

你可能感兴趣的文章
SimpleHibernateDao更新
查看>>
HBase在淘宝的应用和优化小结
查看>>
linux 设备文件
查看>>
利用Shell脚本实现自动备份VPS数据到Dropbox
查看>>
game system misc
查看>>
alg--动态规划(dynamic planning)
查看>>
JavaScript和Ajax部分(3)
查看>>
python装饰器(备忘)
查看>>
openfile
查看>>
Django表单的简单应用
查看>>
java时间工具类
查看>>
【NOIP 2016】Day1 T2 天天爱跑步
查看>>
[设计模式]工厂模式
查看>>
(一)C++内联函数
查看>>
(三)在js(jquery)中获得文本框焦点和失去焦点的方法
查看>>
vim快捷键
查看>>
Centos7下单机部署Solr7.3
查看>>
SqlMetal.exe ORM代码生成
查看>>
copy the content of a file muliptle times and save as ordered files:
查看>>
【基础复习】六:面向对象
查看>>