设计一个程序 copy.java 可以实现文件的拷贝操作
要求:模仿dos的copy命令,输入两路经名,完成copy操作,
执行如: java Copy c:\\bbb\from.txt d:\\aaa\tar.txt

解决方案 »

  1.   

    是滴,不小心发了两个贴,不过分数照给,
        刚开始学JAVA,所以好多还不理解
      

  2.   

    http://blog.csdn.net/cqcjcc123/archive/2007/07/26/1708613.aspx
    写个main方法利用args[0](from),args[1](to),调用public   boolean   copy(String   from,   String   to)这个方法就行了。
    分都是cqcjcc123的,哪天见着他给他就行了
      

  3.   


    import java.io.*;
    public class Test1 { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
    // TODO Auto-generated method stub 
            
    try{
            String path = args[0]; 
            String path1 = args[1];
    FileReader fr=new FileReader(path); 
    BufferedReader br=new BufferedReader(fr); 
    FileWriter fw=new FileWriter(path1); 
    BufferedWriter bw=new BufferedWriter(fw); 
    String s=br.readLine(); 
    while(s!=null) 

    bw.write(s); 

    br.close(); 
    bw.close(); 

    catch(Exception e) 

    e.printStackTrace(); 

    }
    }
      

  4.   

     public static void copy(String s1,String s2)
     {
     try{ 
    FileReader fr=new FileReader(s1); 
    BufferedReader br=new BufferedReader(fr); 
    FileWriter fw=new FileWriter(s2); 
    BufferedWriter bw=new BufferedWriter(fw); 
    String s=br.readLine(); 
    while(s!=null) 

    bw.write(s); 
    System.out.println(s); 
    bw.newLine(); 
    s=br.readLine(); 
    bw.flush();

    br.close(); 
    bw.close(); 

    catch(Exception e) 
    {  e.printStackTrace(); 

     }
      

  5.   

    package iostream;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;import javax.imageio.stream.FileImageInputStream;public class CopyFile { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    FileInputStream fis=new FileInputStream("D:/s.txt");
    FileOutputStream fos=new FileOutputStream("D:/count.txt");
    int read=fis.read();
    while(read!=-1)
    {
    fos.write(read);
    read=fis.read();
    }
    fis.close();
    fos.close();
    File f=new File("D:/s.txt");
    f.delete();} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } }}