[an error occurred while processing this directive]
Domain for sale!
Start Search Contents Index Links About
CopyFile.java
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * An extremly simple (and fragile) copy utiliy. For further enhancments,
 * please see that article at 
 
 @author Havard Rast Blok
 *
 */
public class CopyFile {
  
  private File src;
  
  private File dest;
  
  public CopyFile(File src, File dest) {
    this.src = src;
    this.dest = dest;
  }
  
  /**
   * Copy the specified file of this class to the specifed destination.
   
   @throws IOException if any open, create, read or write error occurs.
   */
  public void copy() throws IOException {
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(src));
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
    
    int b;
    while( (b = in.read()) != -1) {
      out.write(b);
    }
    
    in.close();
    out.close();
  }
  
  /**
   * This utility takes two arguments, destination and host:
   * java CopyFile <source file> <destination file>
   
   */
  public static void main(String[] args) {
    CopyFile cp = new CopyFile(new File(args[0])new File(args[1]));
    try {
      cp.copy();
    catch (IOException e) {
      System.out.println("An error occured while coping the file: ");
      e.printStackTrace();
    }
  }
  
  

}


site: Håvard Rast Blok
mail:
updated: 16 July 2010