你的原贴我已答过,现来抢分size=is.read(b);
请注意size,自己处理一下,
os.write(a,0,size);//write(byte[] b, int off, int len)

解决方案 »

  1.   

    /*
     * Created on 2004-9-11
     *
     * To change the template for this generated file go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    package copy;import java.io.FileInputStream;
    import java.io.FileOutputStream;/**
     * @author 崔占民
     *
     * To change the template for this generated type comment go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    public class Copy
    {
    final private static int INT_READLEN = 10240; public static void main(String[] args)
    {
    if (args.length == 0 || (args.length == 1 && !args[0].equals("/?")))
    {
    System.out.println("command syntax is invalidity!");
    return;
    }
    else if (args[0].equals("/?"))
    {
    System.out.println("copy SrcFile DesFile");
    System.out.println("SrcFile: Source File.");
    System.out.println("DesFile: destination File.");
    return;
    }
    Copy cpy = new Copy(args[0], args[1]);
    } Copy(String aStrSrcFile, String aStrDesFile)
    {
            super ();
    if (aStrSrcFile.equals("") || aStrDesFile.equals(""))
    {
    System.out.println("please input SrcFile and DesFile!");
    System.out.println("copy SrcFile DesFile");
    return;
    } FileInputStream in = null;
    FileOutputStream out = null;
    try
    {
    int bytes = 0;
    byte[] bteFile = new byte[INT_READLEN];
    in = new FileInputStream(aStrSrcFile);
    out = new FileOutputStream(aStrDesFile); while ((bytes = in.read(bteFile)) != -1)
    {
    out.write(bteFile, 0, bytes);
    }

    System.out.println("File Copy finished!");
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    }
    finally
    {
    try
    {
    in.close();
    out.close();
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    return;
    }
    }
    }
    }