import java.io.*;
public class Test{ public static void main(String[] args) { if(args.length<3) { System.out.println(args.length); return; } else{ java.io.File f1=new File(args[0]); java.io.File f2=new File(args[1]); java.io.File path=new File(args[2]); String newname; if(f1.isFile()&&f2.isFile()&&path.isDirectory()) { try{ String fn1=f1.getName(); fn1=fn1.substring(0,fn1.lastIndexOf(".")); String fn=f2.getName(); newname=fn1+fn.substring(fn.lastIndexOf("."),fn.length()); newname=path.getCanonicalPath()+newname; File f3=new File(newname); if(!f3.exists()) f3.createNewFile(); java.io.DataInputStream ids=new java.io.DataInputStream(new FileInputStream(f2)); java.io.DataOutputStream ods=new java.io.DataOutputStream(new FileOutputStream(f3)); byte[] bt=new byte[4096]; while(ids.available()>0){ ids.read(bt); ods.write(bt); } ids.close(); ods.close(); }catch(Exception e){ e.printStackTrace(); return; } System.out.println("file "+f2.getAbsolutePath()+" successfully copied to "+newname); } } } } |
|
来自: Vincent-Hu > 《我的图书馆》