当前位置:网站首页>Realization of file copy
Realization of file copy
2020-11-08 21:03:00 【8Years】
public class TestIO01 {
public static void main(String[] args) {
copy("D:/aaa.txt","D:/B.txt");// Copy the contents of the former file into the latter 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]所创,转载请带上原文链接,感谢
边栏推荐
- Server side resolution of lengthfieldbasedframedecoder of GetBytes
- Five phases of API life cycle
- Looking for better dynamic getter and setter solutions
- The interface testing tool eolinker makes post request
- EntityFramework Core上下文实例池原理分析
- Django之简易用户系统(3)
- 200人的程序员面试经验,都在这里了
- Experiment 1 assignment
- CMS garbage collector
- 进程 线程 协程
猜你喜欢
Problem solving templates for subsequence problems in dynamic programming
实现图片的复制
Using annotation + interceptor to implement asynchronous execution
Swagger介绍和应用
为什么需要使用API管理平台
Part 1 - Chapter 2 pointer operation
接口测试工具Eolinker进行post请求
Flink series (0) -- Preparation (basic stream processing)
[200 interview experience], programmer interview, common interview questions analysis
Learn volatile, you change your mind, I see
随机推荐
Mongodb database
To introduce to you, this is my flow chart software—— draw.io
iptables从入门到掌握
Five design schemes of singleton mode
选择排序
Proficient in high concurrency and multithreading, but can't use ThreadLocal?
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
接口测试工具Eolinker进行post请求
Process thread coroutine
Suffix expression to infix expression
Django之简易用户系统(3)
Constructors and prototypes
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
数组初相识
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
C / C + + learning diary: original code, inverse code and complement code
Decorator (1)
动态规划设计:最大子数组
Copy the picture
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?