import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class CopyFileDemo{
public static void main(String[] args){
String desPathStr = "C:\\Users\\Administrator\\Desktop";
String srcPathStr = "F:\\file.txt";
copyFile(srcPathStr, desPathStr);
}
private static void copyFile(String srcPathStr, String desPathStr) {
String newFileName = srcPathStr.substring(srcPathStr.lastIndexOf("\\")+1);
System.out.println(newFileName);
desPathStr = desPathStr + File.separator + newFileName;
System.out.println(desPathStr);
try{
FileInputStream fis = new FileInputStream(srcPathStr);
FileOutputStream fos = new FileOutputStream(desPathStr);
byte datas[] = new byte[1024*8];
int len = 0;
while((len = fis.read(datas))!=-1){
fos.write(datas,0,len);
}
fis.close();
fis.close();
}catch (Exception e){
e.printStackTrace();
}
}
}