---
title: "Java 仿 dos copy"
author: "windy2coast"
date: "2007-11-02T20:26:36Z"
tags: []
slug: "java-dos-copy"
draft: false
lastmod: "2007-11-02T20:26:36Z"
id: 137683
url: "https://windy2coast.iteye.com/blog/137683"
---

java 代码

01. import java.io.* ;
02. public class Copy
03. {
04. public static void main(String args\[])
05. {
06. if(args.length!=2)
07. {
08. System.out.println("请输入正确的格式的参数: (例如:java Copy d:\\\\\\\\input.txt d:\\\\\\\\output.txt") ;
09. return ;
10. }
11. else
12. {
13. File file1 = new File(args\[0]) ;
14. File file2 = new File(args\[1]) ;
15. copyFile(file1,file2) ;
16. }
17. }
18. public static void copyFile(File srcfile,File desfile)
19. {
20. byte\[] b = new byte\[512] ;//512可以改成其它大于零的适当整数值
21. int len = 0 ;
22. try
23. {
24. FileInputStream fis = new FileInputStream(srcfile) ;
25. FileOutputStream fos = new FileOutputStream(desfile) ;
26. while((len=fis.read(b))!=-1)//循环以512字节拷贝,知道拷贝完.
27. {
28. fos.write(b,0,len) ;
29. }
30. fis.close() ;
31. fos.close() ;
32. }
33. catch(Exception e)
34. {
35. System.out.println(e) ;
36. }
37. }
38. };