Insights

Copiar un Archivo a Otro en Java

1 min read.
CN Camilo Nova Camilo Nova

Camilo Nova

CEO
Subscribe to our newsletter

El siguiente c贸digo muestra como hacer una copia exacta de un archivo a otro en java:

import java.io.*;

public class FileCopy {
    public FileCopy(String sourceFile, String destinationFile) {
        System.out.println("Desde: " + sourceFile);
        System.out.println("Hacia: " + destinationFile);

        try {
            File inFile = new File(sourceFile);
            File outFile = new File(destinationFile);

            FileInputStream in = new FileInputStream(inFile);
            FileOutputStream out = new FileOutputStream(outFile);

            int c;
            while( (c = in.read() ) != -1)
                out.write(c);

            in.close();
            out.close();
        } catch(IOException e) {
            System.err.println("Hubo un error de entrada/salida!!!");
        }
    }

    public static void main(String args[]) {
        if(args.length == 2)
            new FileCopy(args[0], args[1]);
        else
            System.out.println("Debe ingresar dos parametros");
    }
}

Written by Camilo Nova

CN Camilo Nova Camilo Nova

Software Engineer, Investor, CEO, and father of two. Camilo writes on the intersection of technology, design, and business.

Subscribe to our newsletter (free, no ads) With Love 馃拰

Wait. There's more:

Rich Internet Application

Leyendo un poco en Internet sobre entornos enriquecidos en plataformas WEB y sobre tecnolog铆as de desarrollo WEB, encontr茅 un...

1 min read.

Build to
Inspire