• Como Copiar Archivos en Java

    Otro snippet para tener bien a mano. De esta manera podemos copiar archivos binarios o ascii.

    String source = "c:/myfile.x";
    String destiny = "c:/mycopy.x";
    File sourceFile = new File(source);
    File destinyFile = new File(destiny);
    InputStream in = new FileInputStream(sourceFile);
    
    OutputStream out = new FileOutputStream(destinyFile);
    
    byte[] buf = new byte[2048];
    int len;
    while ((len = in.read(buf)) > 0) {
    	out.write(buf, 0, len);
    }
    in.close();
    out.close();
    

    Tags: ,

Leave a comment