当前位置:网站首页>文件拷贝的实现
文件拷贝的实现
2020-11-08 21:03:00 【8Years】
public class TestIO01 {
public static void main(String[] args) {
copy("D:/aaa.txt","D:/B.txt");//把前者文件的内容拷贝到后者文件中qu
}
public static void copy(String srcfile,String destpath) {
File file=new File(srcfile);
File file1=new File(destpath);
InputStream is=null;
OutputStream os=null;
try {
is=new FileInputStream(file);
os=new FileOutputStream(file1);
byte[] car=new byte[3];
int temp;
int len;
while((len=is.read(car))!=-1){
os.write(car,0, len);
String str=new String(car,0,len);
}
os.flush();
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}finally{
try{
if(is!=null){
is.close();
}
}catch (IOException ioException){
ioException.printStackTrace();
}
try{
if(is!=null){
is.close();
}
}catch (IOException ioException){
ioException.printStackTrace();
}
}
}
}
版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4583813/blog/4707700
边栏推荐
- ITerm2 配置和美化
- Express framework
- 如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?
- Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
- CMS garbage collector
- Tasks of the first week of information security curriculum design (analysis of 7 instructions)
- [cloud service] there are so many ECS instances on alicloud server, how to select the type? Best practice note
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
- Regular backup of WordPress website program and database to qiniu cloud
- WordPress网站程序和数据库定时备份到七牛云图文教程
猜你喜欢
随机推荐
Deep copy
Using annotation + interceptor to implement asynchronous execution
An online accident caused by improper use of thread pool
Flink series (0) -- Preparation (basic stream processing)
Case analysis of entitycore framework
Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
动态规划答疑篇
【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!
net.sf.json.JSONObject对时间戳的格式化处理
Leetcode 45 jumping game II
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
[cloud service] there are so many ECS instances on alicloud server, how to select the type? Best practice note
JVM真香系列:轻松理解class文件到虚拟机(上)
Chapter five
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
为什么需要使用API管理平台
Development and deployment of image classifier application with fastai
选择排序