package com.itcast.File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**文件复制api
-
@author wangqiang
-
@version V1.0
-
@date 2019/2/16 15:39
*/
public class CopyFile {
public static void main(String[] args) {
try {
//读文件
RandomAccessFile r=new RandomAccessFile(new File(“c:\timg.jpg”),“r”);
//写文件
RandomAccessFile rw=new RandomAccessFile(new File(“c:\Temp\timg.jpg”),“rw”);
byte[] bytes = new byte[1024];
int len;
while ((len=r.read(bytes))!=-1){
rw.write(bytes,0,len);
}
r.close();
rw.close();} catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("文件copy success");
}
}