import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class test{
public static void main(String[]args) throws Exception{
String sourceFilePath="C:\\Users\\wuxueping\\Desktop\\1.jpg";
String destFilePath="C:\\Users\\wuxueping\\Desktop\\2.jpg";
copyFile(sourceFilePath,destFilePath);
}
public static void copyFile(String sourceFilePath,String destFilePath) throws Exception{
File sourceFile=new File(sourceFilePath);
File destFile=new File(destFilePath);
InputStream in=new FileInputStream(sourceFile);
OutputStream out=new FileOutputStream(destFile);
int len=0;
byte[]data=new byte[1024];
long start=System.currentTimeMillis();
while((len=in.read(data))!=-1){
out.write(data,0,len);
}
long end=System.currentTimeMillis();
System.out.println("共耗时:"+(end-start)+"毫秒");
}
}
java--IO--资源拷贝
猜你喜欢
转载自blog.csdn.net/weixin_42365095/article/details/84931674
今日推荐
周排行