package pbt.iotest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/** 
 * Exemple d'utilisation des classes 
 *  - {@link InputStream}
 *  - {@link OutputStream}
 *  - {@link FileInputStream}
 *  - {@link FileOutputStream}
 * @author pbt
 */
public class Cp {
    public static void main ( String[] args ) { 
    	final String USAGE = "Usage: java Cp <infile> <outfile>" ;
    	InputStream in ;
    	OutputStream out ;
    	int b ; 	// byte lu

    	if ( args.length != 2 ) {
    	    System.out.println(USAGE);
    	    System.exit(1) ; 
    	}
    	// Dans la suite, le nombre de paramètres est correct. 
    	try {
    	    in = new FileInputStream(args[0]) ; 
    	    out = new FileOutputStream(args[1]) ;
    	    while ( (b=in.read()) != -1 ) {
    	    	out.write(b) ; 
    	    }
    	    in.close() ;
        	out.close() ; 
    	} catch ( IOException ioe) {
    	    System.err.println("IO problem" + ioe.getMessage());
        }
    }
}

