Java Copy File copyFiles(String strPath, String dstPath, String srcExtension)

Here you can find the source of copyFiles(String strPath, String dstPath, String srcExtension)

Description

copy Files

License

BSD License

Declaration

public static void copyFiles(String strPath, String dstPath, String srcExtension) throws IOException 

Method Source Code

//package com.java2s;
/*L/*from www .  j ava2 s  .  c o  m*/
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */

import java.io.*;

public class Main {
    public static void copyFiles(String strPath, String dstPath, String srcExtension) throws IOException {
        // if I remove all condition then it throws exception which I wrote below
        /* if ((src.getName().equals("admin")) ||
        (src.getParentFile().getParentFile().getName().equals("presentation")) ||
        (src.getName().equals("cashteam")) &&
        (src.isDirectory()))
        ; // Do not copy anything under this.
            
        elseif (src.isDirectory())
        */
        File src = new File(strPath);
        File dest = new File(dstPath);

        if (src.isDirectory()) {
            //if(dest.exists()!=true)
            dest.mkdirs();
            String list[] = src.list();

            for (int i = 0; i < list.length; i++) {
                String dest1 = dest.getAbsolutePath() + "\\" + list[i];
                String src1 = src.getAbsolutePath() + "\\" + list[i];
                copyFiles(src1, dest1, srcExtension);
            }
        } else if (strPath == null || strPath.endsWith(srcExtension)) {
            FileInputStream fin = new FileInputStream(src);
            FileOutputStream fout = new FileOutputStream(dest);
            int c;
            while ((c = fin.read()) >= 0)
                fout.write(c);
            fin.close();
            fout.close();
        }
    }
}

Related

  1. copyFiles(String p_source, String p_target)
  2. copyFiles(String srcFilePath, String destFilePath)
  3. copyFiles(String srcFolderStr, String destFolderStr)
  4. copyFiles(String srcPath, String destPath)
  5. CopyFiles(String strOrgFile, String strDestFile, boolean bFailIfExists)
  6. copyFiles(String[] sourceFiles, String toDir, boolean overwrite)
  7. copyFileSafe(File destinationFileName, File sourceFileName)
  8. copyFileSafe(File in, File out)
  9. copyFilesBinary(String srcFile, String destDir)