import java.io.File;import java.io.InputStream;import java.io.OutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;public class CreatDirectory{ public static void main(String[] args) throws Exception { Copy(args); } public static void Copy(String args[]) throws Exception { File SourcePath=null; File TargetPath=null; if(args.length==2) { SourcePath=new File(args[0]); TargetPath=new File(args[1]); if(SourcePath.getParentFile()==null) { System.out.println("暂不支持整个分区的文件拷贝!"); } else if(SourcePath.exists()) { if(TargetPath.getName().indexOf(".")==-1) { TargetPath.mkdirs(); File tempFile=new File(TargetPath.getPath()+File.separator+SourcePath.getName()); readWriteFile(SourcePath,tempFile); } else { String s=TargetPath.getParent(); (new File(s)).mkdirs(); readWriteFile(SourcePath,TargetPath); } } else { System.out.println("源文件不存在!"); } } else { System.out.println("您输入命令格式不正确!\n\t例如:java CreatDirectory c:\\123.txt d:\\"); } } public static void readWriteFile(File sourceFile,File targeFile) throws Exception { InputStream input=new FileInputStream(sourceFile); OutputStream output=new FileOutputStream(targeFile); int temp=0; while((temp=input.read())!=-1) { output.write(temp); } input.close(); output.close(); }}