java 代码
- import java.io.* ;
- public class Copy
- {
- public static void main(String args[])
- {
- if(args.length!=2)
- {
- System.out.println("请输入正确的格式的参数: (例如:java Copy d:\\\\input.txt d:\\\\output.txt") ;
- return ;
- }
- else
- {
- File file1 = new File(args[0]) ;
- File file2 = new File(args[1]) ;
- copyFile(file1,file2) ;
- }
- }
- public static void copyFile(File srcfile,File desfile)
- {
- byte[] b = new byte[512] ;//512可以改成其它大于零的适当整数值
- int len = 0 ;
- try
- {
- FileInputStream fis = new FileInputStream(srcfile) ;
- FileOutputStream fos = new FileOutputStream(desfile) ;
- while((len=fis.read(b))!=-1)//循环以512字节拷贝,知道拷贝完.
- {
- fos.write(b,0,len) ;
- }
- fis.close() ;
- fos.close() ;
- }
- catch(Exception e)
- {
- System.out.println(e) ;
- }
- }
- };