想用现成的话,有个办法,用ant的包中的copyfile task

解决方案 »

  1.   

    /**
     * copyÎļþ
     * @param oFile Ô´Îļþ
     * @param tFile Ä¿±êÎļþ
     * @param delFile ÊÇ·ñɾ³ýÔ´Îļþ
     * @return boolean copyÊÇ·ñ³É¹¦
     * @throws FileNotFoundException Ô´ÎļþûÓз¢ÏÖʱÅ׳ö´ËÒì³£
     */
    public static boolean copyFile(File oFile, 
       File tFile, 
       boolean delFile) 
       throws FileNotFoundException {
    if(!oFile.exists()) throw new FileNotFoundException(new StringBuffer("file[")
    .append(oFile.getName()).append("] not found!").toString());
    try {
    byte[] b = new byte[1024];
    int readLen = 0;
    FileInputStream fin = new FileInputStream(oFile);
    FileOutputStream fout = new FileOutputStream(tFile);
    while((readLen = fin.read(b, 0, b.length)) != -1) {
    fout.write(b, 0, readLen);
    }
    fin.close();
    fout.close();
    if(delFile) oFile.delete();
    return true;
    } catch(IOException ex) {}
    return false;
    }