java IO流文件拷贝文件(字符流标准写法)
2024-09-06 18:51:28
public static void copyFile2(String path1, String path2) {
Reader reader = null;
Writer writer = null;
try {
// 打开流
reader = new FileReader(path1);
writer = new FileWriter(path2); // 进行拷贝
int ch = -1;
char [] arr=new char[1024];
while ((ch = reader.read(arr)) != -1) {
writer.write(arr,0,ch);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// 关闭流,注意一定要能执行到close()方法,所以都要放到finally代码块中
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
最新文章
- Windows环境安装Linux系统及JDK部署
- paper 117:image matting 数字抠图
- MySQL + Atlas --- 部署读写分离
- 基本概率分布Basic Concept of Probability Distributions 7: Uniform Distribution
- git config --global core.autocrlf false
- 很好的一篇讲LTP在编解码中的作用的文章
- 使用spring-test报异常org.springframework.asm.ClassReader.<;init>;(Unknown Source)
- sql server多表数据批量更新
- 惊艳的随机化方法 -World Search (homework-04)
- C#使用DataSet类、DataTable类、DataRow类、OleDbConnection类、OleDbDataAdapter类编写简单数据库应用
- oracle DBLink
- js中运动框架的封装
- 网页版仿Excel效果组件--handsontable拓展运用
- 三剑客之grep
- IIS7 配置Http重定向到Https
- ping -c 3 localhost
- GeneralizedLinearAlgorithm in Spark MLLib
- MVC 5使用ViewData(对象)显示数据
- html如何设置打印样式?
- spring cloud 服务提供者
热门文章
- hlt instruction with IF=0
- 【DP】区间DP入门
- free online linux terminal &; github cli online
- js &; replaceAll &; non-global RegExp bug
- Azure &; FaaS in Action
- PWA &; TWA
- c++ 动态解析PE导出表
- flutter 自定义TabBar
- 谷歌地球服务器";失联";的替代方案
- m1款MacBook Air 使用3个月总结及原生运行于apple架构软件推荐