Changeset 5961


Ignore:
Timestamp:
2003-11-25T11:39:30+13:00 (20 years ago)
Author:
kjdon
Message:

added a copy file method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java

    r5261 r5961  
    176176                        String filename) {
    177177    return collectionBaseDir(site_home, coll_name) + File.separatorChar+
    178         "etc" + File.separatorChar + filename;
     178        "transform" + File.separatorChar + filename;
    179179    }
    180180   
     
    329329    }
    330330   
     331    public static boolean copyFile(File source, File destination) {
     332    if (!source.isFile()) {
     333        System.err.println("GSFile.copyFile(): "+source.getPath()+" is not a file!");
     334        return false;
     335    }
     336    try {
     337        destination.getParentFile().mkdirs();
     338        FileInputStream in = new FileInputStream(source);
     339        FileOutputStream out = new FileOutputStream(destination);
     340        int value = 0;
     341        while((value = in.read()) != -1) {
     342        out.write(value);
     343        }
     344        in.close();
     345        out.close();
     346    } catch (Exception e) {
     347        System.err.println("GSFile.copyFile(): something went wrong copying "+source.getPath()+" to "+destination.getPath());
     348        System.err.println("Exception: "+e.getMessage());
     349        return false;
     350    }
     351
     352    return true;
     353    }
    331354    /** Recursively moves the contents of source file to destination,
    332355     * maintaining paths.
     
    375398    return true;
    376399    }
    377    
     400    
    378401}
Note: See TracChangeset for help on using the changeset viewer.