import java.io.*;

/**
* @Description:
* @projectName:JavaTest
* @see:PACKAGE_NAME
* @author:郑晓龙
* @createTime:2019/5/2 22:41
* @version:1.0
*/
public class CopyFile {
public static void main(String[] args) {
copy("d:/abc.txt","d:/def.txt");
} public static void copy(String source, String target) {
// 1、创建源
File src = new File(source);
File dest = new File(target); // 2、选择流
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(src);
os = new FileOutputStream(dest); // 3、操作流
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) != -1) {
os.write(buf, 0, len);
}
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//4、关闭流(先打开的后关闭)
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

  

最新文章

  1. smartComplete——轻量级的autoComplete插件,开源
  2. 桌面oracle 11g导入多年库的dump备忘
  3. SQL Server 查看正在运行的事务信息的 2 种方法。
  4. JavaScript 语言中的 this
  5. python笔记一(正则表达式)
  6. EF实现批量插入
  7. Mixing a dll boost library with a static runtime is a really bad idea错误的解决
  8. Go语言学习笔记(二) [变量、类型、关键字]
  9. CodeForces834D DP + 线段树
  10. 使用python爬虫爬取股票数据
  11. Linux中的Wheel组的作用
  12. insert-interval 插入区间
  13. DeepNLP的核心关键/NLP词的表示方法类型/NLP语言模型 /词的分布式表示/word embedding/word2vec
  14. WopiServerTutorial
  15. C# Web Service 初级教学
  16. Python安装setuptools遇到的MARKER_EXPR错误
  17. JVM内存分配原理
  18. 杂项-操作系统-百科:Solaris
  19. 第十八章:自定义splash screen、app icon和tab icon
  20. linux 监控网卡实时流量iftop

热门文章

  1. FTP配置多用户多目录多权限
  2. Python简单http服务实现
  3. 你都这么拼了,面试官TM怎么还是无动于衷?
  4. RocketMQ系列(四)顺序消费
  5. PyQt5 模块modules
  6. hql 转 sql
  7. <VCC笔记> 关于Assertion
  8. 【SEED Labs】Public-Key Infrastructure (PKI) Lab
  9. 深度学习中损失函数之RMS和MES
  10. Jmeter各种组件