FileDocCategorySizeDatePackage
FileUtility.javaAPI DocExample1516Sun Mar 28 19:08:18 BST 1999com.macfaq.io

FileUtility

public class FileUtility extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmove(java.io.File src, java.io.File dst, boolean overwrite)

  
    if (src.equals(dst)) return;
    
    if (src.isDirectory()) {
      throw new IOException("Can't move directories");
    }
    
    if (dst.isFile() && overwrite) { 
      move(src, dst);     
    }
    else if (dst.isFile() && !overwrite) {
      throw new IOException(dst + " exists");
    }
    else if (dst.isDirectory()) {
      move(src, new File(dst, src.getName()));         
    }
    // try to figure out whether user wanted a to move to a new directory
    // or a new file
    else if (dst.getPath().endsWith(System.getProperty("file.separator"))) {
      if (!dst.mkdirs()) {
        throw new IOException("Could not create " + dst);
      }
      move(src, new File(dst, src.getName()));         
    }
    else {  
      String dir = dst.getParent();
      String name = dst.getName();
      if (dir != null) {
        if (!(new File(dir)).mkdirs()) {
          throw new IOException("Could not create " + dir);
        }
      }
      move(src, dst);           
    }
    
  
private static voidmove(java.io.File src, java.io.File dest)

  
    FileInputStream fin = new FileInputStream(src);
    FileOutputStream fout = new FileOutputStream(dest);
    StreamCopier.copy(fin, fout);
    fout.close();
    fin.close();
    src.delete();